Is there Flow's version of flatMapIterable?

Viewed 471

I have started using Kotlin Flow. Now I'm struggling to map elements from a list, returned by api, one by one. Is there an operator available that does something like RxJava's flatMapIterable?

For example, when the Flow has an ArrayList<T>, then I want to make an operation on every element of that list, and get it as a new Flow.

1 Answers

You can use flatMapMerge operator to achieve the desired result. You can convert a Flow<List<T>> to Flow<T> this way:

yourFlow.
   flatMapMerge { it.asFlow() }

This way you can further process the stream from every element of the initial list using the default Flow operators.

Here is the doc: flatMapMerge

Related