Match Patterns For Scala Classes
Pattern matching on case classes is straightforward because it provides extractor patterns out of the box.
If we need to apply pattern matching to your class, Implement unapply method and match patterns like magic.
Please look at the following code snippet about how to implement unapply and how it provides values to the matched cases under the hood.