Mikael Alfredsson
06/01/2021, 12:16 PMval result = state.transformLatest {
when (it) {
"a" -> emitAll(emitter("A"))
"c" -> emitAll(emitter("C"))
}
}
result.collect {
println(it)
}
this will print a flow of A+<counter> or “C” +<counter> depending on the last value from “state”.
I would like to ignore “unknown” states, but since transformLatest cancels the previous flow even if i don’t emit anything new, setting the state to “B” will just cancel the output, not continue on the previous selected output. Is there a nice way to achieve what I want?wasyl
06/01/2021, 12:29 PMtransformLatest
?Mikael Alfredsson
06/01/2021, 12:29 PMstate.filter{it=="a" || it=="c"}.transformLatest
wasyl
06/01/2021, 2:35 PMtransform
isn’t that straightforward I think). I’d probably just go for some pattern like Map<String, ???>
so that I have single source of truth for filter { handlers.contains(it) }
and for the transformMikael Alfredsson
06/01/2021, 2:37 PMmapOf<State, Flow<String>>
and filterdarkmoon_uk
06/01/2021, 3:07 PMmyFlow
.filter { it.isNotUnknown() }
.distinctUntilChanged()
.flatMapLatest {
// Choose output flow
}
bezrukov
06/03/2021, 3:41 PMstate.mapNotNull {
when (it) {
"a" -> emitter("a")
"b" -> emitter("b")
else -> null
}
}.flatMapLatest { it }