By Alvin Alexander. Last updated: October 13, 2022
Here’s a little Scala 3 enum
match/case expression example:
enum Suit: case Clubs, Diamonds, Hearts, Spades @main def dottyEnumTest = import Suit.* def printEnum(suit: Suit) = suit match case Clubs => println("clubs") case Diamonds => println("diamonds") case Hearts => println("hearts") case Spades => println("spades") printEnum(Clubs) printEnum(Diamonds) printEnum(Hearts) printEnum(Spades)
I don’t know how other people feel, but I really enjoy using the new Scala/Dotty syntax without curly braces.
this post is sponsored by my books: | |||
#1 New Release |
FP Best Seller |
Learn Scala 3 |
Learn FP Fast |