Is there any difference between `.conflate().map {...
# flow
m
Is there any difference between
.conflate().map { … }
and
.conflate().mapLatest { … }
?
b
yes. in first case map's body will be processed (for each non-conflated item), while in second it will be cancelled if new item appear.
Copy code
flow {
        repeat(20) {
            emit(it)
            delay(100)
        }
    }.conflate()
        .mapLatest { // change to map to see difference. 
            delay(250)
            it
        }.collect {
            println(it)
        }
If map's body is perfectly supports cooperative cancellation, there is no
conflate()
necessary.
m
Thanks, so
mapLatest
makes the
conflate
pointless and not the other way round 👍
b
Kinda, you can change
delay
in map to
Thread.sleep
and you will see that conflate may be important even with
mapLatest
👍 1