scala Iterable#map vs. Iterable#flatMap

Landon Kuhn picture Landon Kuhn · Jun 29, 2009 · Viewed 21.2k times · Source

What is the difference between the map and flatMap functions of Iterable?

Answer

kikibobo picture kikibobo · Jun 29, 2009

The above is all true, but there is one more thing that is handy: flatMap turns a List[Option[A]] into List[A], with any Option that drills down to None, removed. This is a key conceptual breakthrough for getting beyond using null.