If I have a `List<Flow<String>>` and I...
# coroutines
s
If I have a
List<Flow<String>>
and I want to merge them all into a single
Flow<String>
, what’s the best way to do that?
c
Copy code
flows.merge()
z
How do you want to merge them? Interleaved, concatenated, something else? There’s a merge function that takes flows. You can also turn your list into a Flow, then use
flattenConcat
or
flattenMerge
.
s
I just want whenever one of the children flows emits an event, I want it to turn into an event in the parent flow
i.e. I’m not wanting to do something like an rx zip operator, which I’m assuming is what you’d call
interleaved
?
z
What I meant by “interleaved” is what you want. Vs “concatenated” which means you emit all the items of one flow until it completes, and only then start emitting items from the next flow.
You can use one of the merge operators for your case.