We are effectively destructuring our list (OneOrNone
) into one of two parts
One
in the event that a value is available.
None
in the event that no value is available.
Why don't we just write it that way then? Here is the structure of our list:
sealed trait OneOrNone[+A] final case object None extends OneOrNone[Nothing] final case class One[+A](a: A) extends OneOrNone[A]