Writing unapply Methods to Enable Pattern Matching (Scala 3 Video)
In this free Scala training video I show how to write unapply
methods in Scala companion objects to enable pattern matching in match
expressions.
I first show how to write a simple unapply
method that returns a String
, and then I show how a default custom class will not work in a match
expression. Then I show how to properly write an unapply
method so your custom class will work in a match expression.
Update: All of my new videos are now on
LearnScala.dev