Djuro
04/18/2024, 6:39 AMmerge
function of Kotlin flows. In the docs here it says that it doesn't preserve the order of elements.
Do you maybe know of some function that merges multiple flows and preserves the order of elements?Jason deBono
04/18/2024, 7:03 AMDjuro
04/18/2024, 7:29 AMDjuro
04/18/2024, 7:41 AMFlow<Int>
and Flow<String>
Let's say Int
is emitted and then String
is emitted
What I understood is that the `merge`d flow that I collect can first collect String
and then Int
even though Int
was emitted firstJason deBono
04/18/2024, 7:59 AMfun test() = flow {
listOf(
(1..5).asFlow(),
(6..10).asFlow(),
(11..15).asFlow(),
(16..20).asFlow(),
(21..25).asFlow(),
).map { emitAll(it) }
}
test().collect { println(it) }
merge(
(1..5).asFlow(),
(6..10).asFlow(),
(11..15).asFlow(),
(16..20).asFlow(),
(21..25).asFlow(),
).collect { println("Merge ---- $it") }