I'm replacing my current implementation using RxJava
to Coroutines
and Flow
. I'm having some trouble using some Flow
operators.
I'm trying to filter the list of items inside a Flow
before providing it to be collected. (Flow<List<TaskWithCategory>>
)
Here is the example on Rx2
:
repository.findAllTasksWithCategory()
.flatMap {
Flowable.fromIterable(it)
.filter { item -> item.task.completed }
.toList()
.toFlowable()
In the implementation above, I provide a list of TaskWithCategory
filtering by Task
s that are already completed.
How can I achieve this using Flow
?
flatMapMerge
works much simpler than you've shown, you need to provide aFlow
-returning function and it will automatically parallelize the collection of these flows.tasksFlow.flatMapMerge { flow { emit(it.map { transform(it) }) } }
– Skindeep