Hello. What is idiomatic way to merge two flows in precise positions. Assume following code:
val 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 */ }
}