Bottom of the Rabbit Hole: for-comprehensions and monads

This is the third in a series of articles intended for Scala Beginners to understand how to write clean code using Option and Try and Either. Part one introduced these typeclasses and demonstrated how to avoid the awkward “test and unsafe-get” approach by using pattern matching of “map”. Part two introduced a slightly more involved example, and showed the problems encountered by nested map transformations that flatMap was designed to fix.

We were working on an example where we started with a case class Contact: