The last chapter focused on monads and the map and flatMap functions. In this chapter we’re going to focus on just flatMap behavior. Specifically, we’ll look at how to chain flatMap function calls before finally yielding results. For comprehensions actually use flatMap under the hood, so we’ll look at the relationship in detail and explain how for comprehensions work.
Where We Left Off
Hopefully you’re now comfortable with the idea of
flatMap
. We looked at it for the collection classes and for Option. Recall that we used flatMap to map over customer names that may or may not exist in our database. ...