scala – sequence pattern

Sequencepatterns YoucanmatchagainstsequencetypeslikeListorArrayjustlikeyoumatch against case classes. Use the same syntax, but now you can specify any number of elements within the pattern.

shows a pattern that checks for a three-element list starting with zero:
expr match {

case List(0, _, _) => println(“found it”)

case _ =>

}

Leave a comment