https://kotlinlang.org logo
Title
m

Matthew Laser

03/24/2022, 5:48 PM
can anyone provide insight into what the best way to combine two flows is? I’m currentlly using the actual
combine
operator, but it’s not getting me quite the result I’m after. Here’s an example of what I’ve got now
flowOne()
.combine(flowTwo, { a, b -> Pair(a,b) })
.onEach { ... }
While the actual values of the
Pair
i’m creating are correct, as far as I can tell, the values are only updated when
flowOne
emits a value, only then combining with the latest value from
flowTwo
. Is there an elegant operator (or approach) I can use to propagate my
Pair
immediately when either
flowOne
or
flowTwo
update, not just
flowOne
? update: turns out I
combine
is what I want! except, rather than
flowOne.combine(flowTwo)
, I need
combine(flowOne, flowTwo)
:)
i’ve used
zip
in the past with
Rx
but I think that’s also probably not what I’m looking for
m

Michael Marshall

03/25/2022, 2:32 AM
I’m 90% sure
combine(flow1, flow2)
is the same as
flow1.combine(flow2)
Looking at the docs and implementation it seems to match up with my assumption, but I could be wrong.
They should both do what you need