What's the elegant way to have something like `com...
# coroutines
n
What's the elegant way to have something like
combine(flow1, flow2, ..., flowN, transform)
that does not wait for all flows to emit the first value? I'd happily receive a smaller array if some flow does not have a value yet.
e
You can do
onStart { emit(null) }
on each on the source flows to have them immediately emit a null. What are you trying to achieve, though?
n
Yeah I might be doing things the wrong way? I have a
List<Flow<T>>
where each flow retrieves a single
T
item. Retrieval is very expensive. Then I want a
Flow<List<T>>
including all items that satisfy a certain condition, so I'm using
combine(*flows) { it.filter(condition) }
. Works but, waits for all flows, while I'd like to receive incomplete results as well.
Is
onStart { emit(null) }
equivalent to
flow { emit(null); emitAll(flow) }
?
👌 1
e
It might be easier just to do
list.asFlow().flattenMerge(list.size).filter { … }
n
Thanks. I think that works great if the source flows are guaranteed to emit just once, but what I have is state flows which might emit updated values of T over time