julian
07/02/2020, 2:13 AMcompose
operator?
(Rather than operating individual items emitted by a Flow, it would operate on the Flow itself, returning a new composed Flow.)octylFractal
07/02/2020, 2:14 AMoctylFractal
07/02/2020, 2:17 AMfun <T, V> Flow<T>.mapAndFilter(map: suspend (T) -> V, filter: suspend (V) -> Boolean): Flow<V> {
return map(map).filter(filter)
}
or custom logic:
fun Flow<Int>.addThreeToEveryThird(): Flow<Int> {
val original = this
return flow {
var i = 0
original.collect {
i++
when (i % 3) {
0 -> emit(it + 3)
else -> emit(it)
}
}
}
}
julian
07/02/2020, 2:18 AMFlow
that could return a transformed Flow
.julian
07/02/2020, 2:19 AMlouiscad
07/02/2020, 5:53 AMcombine
operator? This one exists as a top level function, and an extension of Flow<*>
.octylFractal
07/02/2020, 5:55 AMcompose
is basically as described above -- it allows the mapping of a Flow<T>
to Flow<V>
as a whole, not based on intermediate elements. It is also not a merging device.