Scala’s unapply
method is often left unconsidered although it presents an elegant way to solve some specific problems.
The situation we’re going to look at in this article is when we need to add constructors (that can possibly failed to a class).
First let’s take a concrete example with a simple value class:
final case class Id(value: Int) extends AnyVal