flatmaps
FlatMap is a higher-order function used in functional programming and many modern languages. It maps each element of a collection to another collection and then flattens the resulting nested structure by one level, yielding a single combined collection. This makes it convenient for operations where each input item can produce multiple output items.
Formally, if you have a collection A and a function f: A -> Collection[B], flatMap returns a Collection[B]
FlatMap is used when the transformation yields multiple results per input, such as splitting strings into words,
Performance characteristics depend on the implementation and the data structure; flatMap typically performs a single traversal
Related concepts include map, flatten, and concatMap; flatMap is a practical shorthand for the common pattern