We learned about pattern matching in the past and there were a lot of “we will learn about this later“.
Some of thelateris today !
One of the big advantage ofcase classoverclassis the built-in support for pattern matching. We are going to see the same advantage withcase objectin a later SKB.
Coming back tocase class. You can perform several test using pattern matching:
case Person(firstName, lastName) => ???case Person(firstName, lastName) if firstName.startsWith("L") => ???case Person("Leo", lastName) => ???case p @ Person("Leo", lastName) => ???case p @ (Person("a", _) | Person(_, "b")) => ???