Skip to content

Instantly share code, notes, and snippets.

@dacr
Last active April 2, 2023 10:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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/7e35d7963dd35d65bc3ba3f4b08ceba564b5acdd
// 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.1.1"
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