Created
July 17, 2017 07:21
-
-
Save stefanobaghino/fb7c1a4071cc741fcb84af4ed2dc060c to your computer and use it in GitHub Desktop.
This file contains 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
object Person { | |
def unapply(arg: Person): Option[(String, Int, Boolean)] = | |
Some(arg.name, arg.age, arg.valid) | |
} | |
trait Person { | |
def name: String | |
def age: Int | |
def valid: Boolean | |
} | |
case class MarriedPerson( | |
name: String, | |
age: Int, | |
valid: Boolean, | |
spouse: Person) extends Person | |
val bob = MarriedPerson("bob", 27, false, null) | |
val alice = MarriedPerson("alice", 27, true, bob) | |
println(alice match { | |
case MarriedPerson("charlotte", _, _, Person("bob", _, _)) => "charlotte is married to bob" | |
case MarriedPerson("alice", _, _, Person("desmond", _, _)) => "alice is married to desmond" | |
case MarriedPerson("alice", _, _, Person("bob", _, _)) => "alice is married to bob" | |
case _ => "no one is married" | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment