Both map and flatMap can be applied to a Stream and they both
return a Stream. The difference is that the map operation produces
one output value for each input value, whereas the flatMap operation
produces an arbitrary number (zero or more) values for each input
value.
This is reflected in the arguments to each operation.
The map operation takes a Function, which is called for each value in
the input stream and produces one result value, which is sent to the
output stream.
The flatMap operation takes a function that conceptually wants to
consume one value and produce an arbitrary number of values. However,
in Java, it’s cumbersome for a method to return an arbitrary number of
values, since methods can return only zero or one value. One could
imagine an API where the mapper function for flatMap takes a value and
returns an arra