O'Reilly logo
  • Alex Buzunov thinks this is interesting:

def mOlder(p: Person): Option[String] = p match {
case Person(name, age, true) if age > 35 => Some(name)
case MarriedPerson(name, _, _, Person(_, age, true))
if age > 35 => Some(name)
case _ => None


Cover of Beginning Scala, Second Edition


This does not compile <console>:13: error: case class MarriedPerson has case ancestor Person, but case -to-case inheritance is prohibited. To overcome this limitation, use extractors to pattern match on non-leaf nodes. case class MarriedPerson(override val name: String,