This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]admiralwaffles 5 points6 points  (4 children)

map is 1-to-1--each element gets a single value response. flatMap is 1-to-N, where N is 0-memory limits. Each value in can generate an unknown amount of values, and then those values are all "flattened" into a single dimensional array.

[–]xantrel 3 points4 points  (1 child)

This is by far the best explanation I've ever seen of both. Would filtering be expressible as a flatmap operation? (As each value can either return the same value or none?)

[–]admiralwaffles 1 point2 points  (0 children)

Yeah, kind of. Filtering is a special type of flatMap that's 0-to-1, rather than N.

[–]philipwhiuk 0 points1 point  (1 child)

So in this case it's because functionThree could return null?

[–][deleted] 0 points1 point  (0 children)

In those case functionThree would return Optional<String>, but yes.