Created
July 12, 2024 21:08
-
-
Save 3xau1o/ec20def838956d0aeb989d087751f07a to your computer and use it in GitHub Desktop.
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
//> 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