Last active
February 3, 2026 20:21
-
-
Save dacr/34ba1378dbcdf2b7cb7b9fab6e99cb96 to your computer and use it in GitHub Desktop.
scala3 feature examples - enums / published by https://github.com/dacr/code-examples-manager #3797fcf0-dedf-427b-b990-3ee62621810d/32149b3f2ee59ece649bada2a295d8b56b1d64e8
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // summary : scala3 feature examples - enums | |
| // keywords : scala3, tutorial, @testable | |
| // publish : gist | |
| // authors : David Crosson | |
| // license : Apache License Version 2.0 (https://www.apache.org/licenses/LICENSE-2.0.txt) | |
| // id : 3797fcf0-dedf-427b-b990-3ee62621810d | |
| // created-on : 2021-03-19T17:06:38+01:00 | |
| // managed-by : https://github.com/dacr/code-examples-manager | |
| // run-with : scala-cli $file | |
| //> using scala "3.4.2" | |
| enum CardColor { | |
| case Red, Black | |
| } | |
| enum CardValue { | |
| case Ace, Two, Three, Four, Five, Six, Seven, Eight, Nine, Ten, Jack, Queen, King | |
| } | |
| enum PaymentMethod { | |
| case WireTransfer(swift:String, iban:String, account:String, recipient:String) | |
| case CreditCard(number:String, expiration:String, securityCode:String, name: String) | |
| } | |
| enum CardSuit(val color:CardColor) { | |
| case Club extends CardSuit(CardColor.Black) | |
| case Diamond extends CardSuit(CardColor.Red) | |
| case Spade extends CardSuit(CardColor.Black) | |
| case Heart extends CardSuit(CardColor.Red) | |
| } | |
| @main def go():Unit = { | |
| println(CardColor.Red) | |
| println(CardColor.Red.ordinal) | |
| println(CardColor.valueOf("Black")) | |
| println(CardSuit.valueOf("Club").color) | |
| val paiement:PaymentMethod = PaymentMethod.CreditCard("424242", "10/20", "042", "John Doe") | |
| println(paiement) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment