July 2018
Intermediate
186 pages
3h 24m
English
Now we will return to pattern matching and learn about extending capabilities behind case classes. As you will remember from the previous chapter, we can use pattern matching against case classes, where fields of a class can be bound to the variables in the scope of an appropriative case clause. Can we do this for our non-case classes and embed our own custom logic for matching?
In this section, we will learn how to write our own pattern matcher and get acquainted with some standard generic classes which are often used with pattern matching.
Now, let's get started with the minimal example.
case class Wrapper(x:Int)
w match {case Wrapper(x) => doSomething(x)}Read now
Unlock full access