flattenMerge() works much like flattenConcat() from the previous lesson. However, it takes a concurrency parameter. If that is set to 1, then flattenMerge() should give you identical output to flattenConcat(), though flattenConcat() is more efficient. However, if concurrency is set to a higher value — it defaults to 16 on Kotlin/JVM, for example — then instead of the inner flows being subscribed to serially, they are subscribed to concurrently, up to the requested level of concurrency.

So, this sample is identical to the flattenConcat() one, other than the switch to flattenMerge(). However, due to concurrency, instead of getting all the 1 objects followed by all the 2 objects and so on, we get interleaved results.

You can learn more about this in:
Run Edit