https://kotlinlang.org logo
Title
m

Marc Knaup

12/25/2020, 4:07 PM
Is there any difference between
.conflate().map { … }
and
.conflate().mapLatest { … }
?
b

bezrukov

12/25/2020, 5:27 PM
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.
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

Marc Knaup

12/25/2020, 5:54 PM
Thanks, so
mapLatest
makes the
conflate
pointless and not the other way round 👍
b

bezrukov

12/25/2020, 6:30 PM
Kinda, you can change
delay
in map to
Thread.sleep
and you will see that conflate may be important even with
mapLatest
👍 1