Scala pattern matching OR

Let's continue the pattern matching exploration.

How would you match several conditions at once ? We are going to learn this today.

Once you know the syntax, it is pretty straight forward, you have to use the symbol|. Like the boolean operatorOR:||.

The syntax is:

case valueName @ ( enum1 | enum2 | enum3 ) => ...

You can also do the same thing without the@:

case ( enum1 | enum2 | enum3 ) => ...

And you can do the same thing withcase class:

case valueName @ ( CaseClass(_, exactMatch) | CaseClass(match2, _) ) => ...

Next time, we are going to dive more into thecase classuse case.

Reveal more information and clues
Load Exercise