January 2020
Intermediate to advanced
470 pages
11h 13m
English
Basically, what flatMap() does is first apply a map() function and then apply flat() to the result of the mapping operation. This is an interesting combination because it lets you produce a new array with a different number of elements. (With the usual map() operation, the output array will be exactly the same length as the input array). If your mapping operation produces an array with two or more elements, then the output array will include many output values, and if you produce an empty array, the output array will include fewer values.
Let's look at a (somehow nonsensical) example. Assume that we have a list of names, such as "Winston Spencer Churchill", "Abraham Lincoln", and "Socrates". Our rule is ...
Read now
Unlock full access