Pattern Matching with Match

In this lesson, you will learn about pattern matching and how it is implemented using the `match` control structure.

Pattern Matching #

Pattern matching means exactly what you think it might—checking if an object or series of tokens match a specified pattern. A pattern match consists of a list of alternative cases which are made up of a pattern and a corresponding expression.

Using match #

In Scala, pattern matching is done using the match expression. It is evaluated by taking the object to be matched and comparing it with each pattern in the order they are listed. The first pattern to match the object expression is selected and the corresponding expression is evaluated.

Syntax #

Create a free account to access the full course.

By signing up, you agree to Educative's Terms of Service and Privacy Policy