> Can someone explain to me the difference between map and flatMap Similarity: Both transform collection A to collection B.
Difference: * map: One element in A is transformed to one element. One -> one. Size of B = size of A. * flatMap: One element in A is transformed to 0 or more elements, then the elements are connected together. One -> many. Size of B >= size of A. Shape of the transformation function: * map: One element in -> one element out. * flatMap: One element in -> 0 or more elements out (a collection). > what is a good use case for each? map and flatMap are very common operation in functional programming. You should easily find examples that demonstrate the properties above, and more info about them on the Internet.