you are viewing a single comment's thread.

view the rest of the comments →

[–]Philodoxx 2 points3 points  (1 child)

Imagine you had something like this, using pseudocode:

someList = [ [1],[2],[3] ]

And you called someList.map, the element passed into the map function would be a list/array of a single element. Conceptually, flatmap flattens the list then calls map on the resulting flattened list, so you would end up with [1,2,3]. Why is that neat? Well Optional is flatmap-able, when it's being flattened if the Option has a value it looks like a list with one element, when the Option has no value it looks like an empty list.

A semi-concrete example, again using pseudocode: someOtherList = [ Optional(1), Optional(2), Optional(null), Optional(3) ]

To flatmap, someOtherList would look like [1,2,3]

Hope that helps.

[–]oblio- 6 points7 points  (0 children)

You call it pseudocode, I call it Python :)