zak.taccardi
05/17/2020, 6:21 PMflowB
when val flowA: Flow<Boolean>
emits true
, and unsubscribe from flowB
when flowA
emits false
?zak.taccardi
05/17/2020, 6:29 PMflowA.distinctUntilChanged()
.flatMapLatest { shouldSubscribe: Boolean ->
if (shouldSubscribe) {
flowB
} else {
emptyFlow()
}
}
.launchIn(this)
zak.taccardi
05/17/2020, 6:29 PMoctylFractal
05/17/2020, 6:37 PMTash
05/17/2020, 6:41 PMflatMapLatest
looks like the way to gogildor
05/18/2020, 8:17 AMswitchMap
is the way to implement this, until I realised that flatMapLatest is the same
Of course I’m biased, too many years of RxJava usage, but still “switch” which actually helps me understand what this function doesTash
05/18/2020, 8:37 AMThis nomenclature produces the following distinctly named variants of• `flatMapConcat`/`flattenConcat` -- concatenates all flows. • `flatMapLatest`/`flattenLatest` -- cancels ongoing flow as soon as the new one appears. • `flatMapMerge`/`flattenMerge` -- concurrently run flows and merge their results. Got more context on the name after reading that.operator with different merging strategies:flatMap
gildor
05/18/2020, 8:45 AMgildor
05/18/2020, 8:45 AM