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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With