class Cat(let name: String, let lives: Int64) class Dog(let name: String, let years: Int64) union Pet of Cat, Dog fun describe(pet: Pet): String = if pet ... is Cat(let name, let lives) { "cat $name has $lives lives" } ... is Dog(let name, let years) { "dog $name is $years of age" } List(Cat("Lila", 7), Dog("Fenton", 6), Cat("Molly", 9)) .retain(|p| p.name.size > 5) .map (|p| describe(p)) .each (|d| println(d)) // → cat Molly has 9 lives // → dog Fenton is 6 years of age