Geert
04/17/2024, 3:14 PMGeert
04/17/2024, 3:20 PMval sf: StateFlow<Int> = MutableStateFlow(0)
var state: Int = sf.value
val someFlow = sf.map {
val diff = it - state
state = it
diff
}
But I feel that there could be some better solution.Peter Farlow
04/17/2024, 3:59 PMPeter Farlow
04/17/2024, 4:00 PMGeert
04/17/2024, 4:20 PMGeert
04/17/2024, 4:20 PMval stateFlow: StateFlow<Int> = MutableStateFlow(0)
stateFlow
.runningFold(0 to 0) { (_, last), next -> last to next }
.map { (last, current) -> last - current }