Hi, the `combine` operator only emits once every f...
# coroutines
c
Hi, the
combine
operator only emits once every flow has an emission. in my case i want to combine flows and it might that one flow would not emit at all - in that case i want to have the transformation receive a null value for not yet existing values of those streams.
Copy code
combineAlways(flow1, flow2) { v1, v2 (null as not yet an emission) ->
...
}
is there a way to achieve that?
t
Can you wrap flow1 and flow2 in each a flow that always emits an initial null value?
c
true, i could send a “dummy” value for the stream which potentially does not emit actual values.
t
Are the types from flow1 and flow2 the same or is it different types?
c
different
e
flow2.onStart { emit(null) }
?
Copy code
combine(
  flow1,
  flow2.onStart { emit(null) },
) { o1, o2? ->
  // ... do your thing
}
c
yep, that’s a workaround. 👍
e
Nitpick but its not a “_workaround”_ 😅, its the K coroutine way
c
ok - i thought there might be a more elegant solution (operator) to that. bc. with that i need to make one flow nullable and also need to know which flow potentially does not emit values
but thanks for your help! 🙂
518 Views