Hello, what's the best way to collect two flows, F...
# flow
g
Hello, what's the best way to collect two flows, Flow A and Flow B, when Flow B needs a value coming from Flow A?
b
FlowA.zip(FlowB) {}
In the lambda you get latest values from both flows
m
Copy code
flowA.flatMapLatest { latestValue ->
    // flowB has access to the latestValue, whenever flowA has new emissions, the collection will be cancelled, and a new latestValue will be emitted.
}
x
Depending on your desired output, you have
zip
,
combine
and
merge
The
flatMapMerge
,
flatMapConcat
and
flatMapLatest
are used to perform an operation on a
Flow
that returns another
Flow
and bring the results together
g
Thank you all !
flatMapLatest
worked like a charm! 💙
👍 1