kmeredith (23) [Avatar] Offline
#1
Chapter 2 notes:

Another big advantage with pattern matching in Scala is that the compiler checks for the
exhaustiveness of the pattern match. If you forgot to insert any of the enumerations of
Balance in the pattern match clause, the compiler will issue a warning.


Perhaps it's implied (or expected to an intermediate Scala user), but I think it'd be helpful to note that the sealed keyword is responsible for exhaustiveness.

scala> trait Parent  // not exhaustive
defined trait Parent

scala> case object Boy extends Parent
defined object Boy

scala> case object Girl extends Parent
defined object Girl

scala> def f(p: Parent): Boolean = p match {
     |   case Boy => true
     | }
f: (p: Parent)Boolean
kmeredith (23) [Avatar] Offline
#2
My mistake, I spoke too soon.

Ch 3 explains sealed traits.

I'll make sure to read the whole book before making comments of this type.