jossiwolf
04/30/2021, 6:02 PMsuspend fun Flow<Boolean>.flippedTo(value: Boolean, block: () -> Unit) {
var previous: Boolean? = null
collect { current ->
if (previous == !value && current == value) {
block()
}
previous = current
}
}
boolFlow.flippedTo(false) {
println("Flipped from true to false")
}
boolFlow.flippedTo(true) {
println("Flipped from false to true")
}
Javier
04/30/2021, 6:07 PMbaxter
04/30/2021, 6:07 PMdistinctUntilChanged
? Or that ☝️