© Toby Weston 2018
Toby WestonScala for Java Developershttps://doi.org/10.1007/978-1-4842-3108-1_19

19. For Comprehensions

Toby Weston
(1)
London, UK
 
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. ...

Get Scala for Java Developers: A Practical Primer now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.