Thomas
04/21/2019, 4:55 PMlouiscad
04/21/2019, 4:56 PMflatMap
?simon.vergauwen
04/21/2019, 5:00 PMNote that FlatMap merges the emissions of these Observables, so that they may interleave.These docs makes comparison with other operators. http://reactivex.io/documentation/operators/flatmap.html
flatMapConcat
or flatMapMerge
look like good examples.Thomas
04/21/2019, 6:25 PMflatMap
doesn’t exist in Flow. Do you mean flatMapConcat
or flatMapMerge
instead? Which one would be the equivalent of switchMap
in Rx?simon.vergauwen
04/21/2019, 6:28 PMflatMapConcat
and seeing how it’s an alias to flatMapMerge(concurrency = 1, bufferSize = 1)
I imagine this behaves as switchMap
but the docs are not extensive enough to confirm that without trying it out unfortunately.
Transforms elements emitted by the original flow by applying transform, that returns another flow, and then concatenating and flattening these flows. This method is identical to flatMapMerge(concurrency = 1, bufferSize = 1)source: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/
Thomas
04/21/2019, 6:30 PMswitchMap
still needs to be added: https://github.com/Kotlin/kotlinx.coroutines/issues/1107
So I think flatMapConcat
works a bit differently but I really don’t know without trying.streetsofboston
04/21/2019, 11:44 PMThomas
04/22/2019, 9:03 AMCancellationException
work?streetsofboston
04/22/2019, 12:03 PMcollect
inside a `launch`ed coroutine. Then cancelling the Job
returned by that launch
looks more idiomatic to me.
Still, I think we'd want a more simple way, more imperative/sequential way of breaking out of a collect
loop.
You can't break out of an Rx subscribe
either, but since coroutines allow for a more imperitive/sequential way of programming, it would be great if Coroutines' collect
would allow a 'break' or 'exit' out of the loop.
Think about having two plain `Collection<T>`s and writing a switchMap
for these two collections just using for
loops...Thomas
04/22/2019, 7:13 PMJob
returned by launch
, just like you explained earlier.