@FlowPreview fun <T, R> Flow<T>.flatMapMerge(
    concurrency: Int = DEFAULT_CONCURRENCY,
    transform: suspend (value: T) -> Flow<R>
): Flow<R>

Transforms elements emitted by the original flow by applying transform, that returns another flow, and then merging and flattening these flows.

This operator calls transform sequentially and then merges the resulting flows with a concurrency limit on the number of concurrently collected flows. It is a shortcut for map(transform).flattenMerge(concurrency). See flattenMerge for details.

Note that even though this operator looks very familiar, we discourage its usage in a regular application-specific flows. Most likely, suspending operation in map operator will be sufficient and linear transformations are much easier to reason about.

Operator fusion

Applications of flowOn, buffer, produceIn, and broadcastIn after this operator are fused with its concurrent merging so that only one properly configured channel is used for execution of merging logic.


concurrency - controls the number of in-flight flows, at most concurrency flows are collected at the same time. By default it is equal to DEFAULT_CONCURRENCY.