You can also say that a flatMap maps an element to a stream of other elements. So it forms a sort of 1-to-many-relation. Suppose we want to form the pairs (1, 1), (1, 2), ..., (1, 5), (2, 2), ..., (2, 5), ... (5, 5).
We can say that if we have a, say, 3, then we want to map this 3 to the pairs (3, 3), (3, 4) and (3, 5). That can be done with:
with
Now, we do not only want to do this for the value of 3, but also for the values 1 up to 5. For each of those numbers, we map that number to the stream above. Since we map each of the elements 1, ..., 5 to a stream of P's, we need a flatMap. So we get: