neworldlt
01/27/2021, 6:48 PMval flowA = (1..10).asFlow()
val flowB = flowOf("a","b", "c", "d", "e")
Result I want to get is: 1, 2, a, 3, 4, b, 5, 6, c, 7, 8, d, 9, 10, e
My current solution is to use ReceiveChannel, but it does not look very idiomatic:
launch {
val channelB = flowB.produceIn(this)
flowA.withIndex().transform { item ->
emit(item)
if (item.index > 0 && item.index % 2 == 1)
emit(flowB.receive())
}.collect { /* something useful */ }
}
knthmn
01/28/2021, 12:53 AMneworldlt
01/28/2021, 10:41 AMMerges the given flows into a single flow without preserving an order of elements.It does not meet my requirement of precise positions