Skip to content

Instantly share code, notes, and snippets.

@dacr
Last active May 25, 2024 10:19
Show Gist options
  • Save dacr/34ba1378dbcdf2b7cb7b9fab6e99cb96 to your computer and use it in GitHub Desktop.
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/3b9a82bb2860802dc806efce9b1c6465fff45c23
// summary : scala3 feature examples - enums
// keywords : scala3, tutorial, @testable
// publish : gist
// authors : David Crosson
// license : Apache NON-AI License Version 2.0 (https://raw.githubusercontent.com/non-ai-licenses/non-ai-licenses/main/NON-AI-APACHE2)
// 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