Option

Option is probably the first effect that a novice Scala developer gets familiar with. It encodes the situation that the function might return no result. Simplified, it is represented in stdlib as an algebraic data type, as shown in the following code:

sealed abstract class Option[+A]
case object None extends Option[Nothing]
final case class Some[+A](value: A) extends Option[A]

None represents the case of an absent result, while Some(value) represents the case where a result exists. Next, we'll look at a three-step approach to gain more understanding of how to work with an Option—how to create it, read the value from it (if there is one) and which possibilities emerge from the fact that Option is an effect.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.128.204.5