Skip to content

Instantly share code, notes, and snippets.

@an0
Created December 5, 2015 03:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save an0/10cbc5c7e711471ba869 to your computer and use it in GitHub Desktop.
Save an0/10cbc5c7e711471ba869 to your computer and use it in GitHub Desktop.
flatMap

box1_of_e1.flatMap(e1 -> box2_of_e2) -> box1_of_e2

  1. Maps every element of the source box to a target box.
  2. If the target box is not empty, unwraps it and puts its content into the source box.
  3. If the target box is empty, ignores it.

So it filters out empty target boxes. But it doesn't filter out empty elements of the source box. The mapping function f must handle empty source elements.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment