February 2018
Intermediate to advanced
552 pages
13h 46m
English
In Scala, pattern matching is one of the powerful FP constructs, which is not available in many other languages, such as Java. It is used to match an expression with a sequence of alternatives and get the required results.
It is something similar to Java's Switch statement, but it does more. One of the greatest benefits of this FP construct is that we can do matching on almost everything, such as values, objects, Case classes, user-defined classes, and more.
The following syntax defines how to use Scala's match statement to do pattern matching:
[Expression] match { case [Pattern1] => [A block of code-1] or [Result-1] case [Pattern2] => [A block of code-1] or [Results2] ... case [Pattern-n] => [A block of code-1] or [Results-n] ...Read now
Unlock full access