Skip to content

Instantly share code, notes, and snippets.

@utenma
Created July 12, 2024 21:08
Show Gist options
  • Save utenma/ec20def838956d0aeb989d087751f07a to your computer and use it in GitHub Desktop.
Save utenma/ec20def838956d0aeb989d087751f07a to your computer and use it in GitHub Desktop.
//> using scala 3.nightly
import language.experimental.namedTuples
type Person = (name: String, age: Int)
type Dog = (name: String, age: Int, breed: String)
type LivingThing = Person | Dog
@main
def main(): Unit =
val test = (1, 2, 3)
type Person = (name: String, age: Int)
val bob: Person = (name = "Bob", age = 33)
val max: Dog = (name = "Max", age = 4, breed = "Husky")
printLivingThing(bob)
printLivingThing(max)
def printLivingThing(lt: LivingThing): Unit =
lt match
case (name, age) => println(s"A person named $name is $age years old")
case (name, age, breed) => println(s"A dog named $name is $age years old and is a $breed")
case _ => println("Something else")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment