Given two streams A and B, I want to merge them su...
# rx
a
Given two streams A and B, I want to merge them such that the merge emits items from A only until B emits. At that point it emits B only. How can I do this? Thanks!
e
could be something like this:
Copy code
var emittedB = false
merge(a.takeWhile { !emittedB }, b.onEach { emittedB = true })
a
so, takeWhile has a stream overload - playing around with that
u
Do not use external states and side effects
e
it's fine if it's encapsulated. if the resulting flow may be subscribed to multiple times,
Copy code
flow {
    var emittedB = false
    emitAll(merge(a.takeWhile { !emittedB }, b.onEach { emittedB = true }))
}
would do