...

/

Types of Patterns

Types of Patterns

In this lesson, you will be given a brief introduction to the different types of patterns you can work with in pattern matching.

In the previous lesson, we were introduced to pattern matching in Scala. In this lesson, we will go over the types of patterns provided in Scala to see the true potential of pattern matching.

Wildcard

We saw the wildcard pattern _ in the previous lesson. It is a pattern which matches with any object. It is often used as a default pattern to avoid runtime errors.

Scala
val wildcardPattern = 75
wildcardPattern match {
case _ => println(s"You said $wildcardPattern")
}

Constant

The food example in the previous lesson was matching constant ...