scala 3

An example of using enums in Scala 3 (Dotty)

Here’s a quick example of how to use Scala 3 (Dotty) enums, including using them as constructor and method parameters, and in a match expression. First, some Scala 3 enums for a pizza store application:

The Scala 3 “Dotty” procedure syntax

As a note to self, the Scala 3 “Dotty” procedure syntax is going to look like this:

def f() = { ... }
def f(): Unit = { ... }

This Scala 2 procedure syntax is being dropped:

def f() { ... }

You can find the official Dotty procedure syntax page at this link.

As for me, I’m adding this page right now because I noticed today that this procedure syntax (without the parentheses) also works with Dotty:

How to create a Scala 3 (Dotty) project with SBT

I can never remember how to create a Scala 3 (Dotty) project with SBT (in early 2019), so:

# create a new Dotty project
sbt new lampepfl/dotty.g8

# create a dotty project that cross compiles with scala 2
sbt new lampepfl/dotty-cross.g8

# start a dotty reply from within your sbt project
$ sbt

> console
scala> _

Here’s what an example interaction looks like — include SBT renaming my directory name to all lowercase, which brings me no joy: