concept pattern match statement in category scala

This is an excerpt from Manning's book Get Programming with Scala.
After discovering how to express interfaces in Scala using a trait, I’ll now introduce you to pattern matching. You can use a pattern matching statement as an alternative to an if…else one, particularly useful when you need to consider have many different condition branches. A pattern matching statement is the equivalent of the switch/case statement of other languages, such as Java, JavaScript, and C++. Pattern matching is more powerful and versatile than a classic switch/case statement thanks to its powerful syntax and dedicated support for sealed element and classes. In this lesson, you’ll learn how pattern matching compares to an if…else statement, and its base uses. You’ll also discover to define a pattern matching statement over a sealed set of values and how the compiler can warn you if you forget to consider any of them. Pattern matching has also dedicated support for classes, but I’ll introduce you to this topic later on when we are going to discuss case classes. In the capstone, you’ll use pattern matching to map country names to their timezones.
Figure 14.1: Syntax diagram on the pattern matching statement in Scala. When pattern matching, you need to declare at least one case condition.
![]()