svenjacobs
08/30/2019, 6:15 AMval flow1 = flowOf(1, 2, 3)
val flow2 = flowOf(4, 5, 6)
val flow3 = flow1.concat(flow2) // = 1, 2, 3, 4, 5, 6
The order of flow3
does not matter here, so it also might be 1, 4, 2, 5, 3, 6
or any other order, depending on how the values are produced in flow1
and flow2
.val flow3 = flow {
flow1.collect { emit(it) }
flow2.collect { emit(it) }
}
is a solution but I'm wondering if there is a simpler solution šlouiscad
08/30/2019, 6:26 AMflatMapConcat
svenjacobs
08/30/2019, 6:34 AMFlow
in the transform function will be applied to any value of flow1
. So if I call flow1.flatMapConcat { flow2 }
the result will be 4, 5, 6, 4, 5, 6, 4, 5, 6
flow1
and flow2
should only be there once in the resulting flow šmarstran
08/30/2019, 7:07 AMflowOf(flow1, flow2).flattenConcat()
svenjacobs
08/30/2019, 7:09 AMflow1
for instance needs 5 seconds before producing the first value but flow2
is faster? Then the first results will still be collected once flow1
has produced it's values. Also what if any of the flows are not terminal?marstran
08/30/2019, 7:35 AMflattenMerge()
.