Chris Fillmore
11/25/2021, 2:35 PMfun <T> Flow<T>.onChange(action: (oldValue: T, newValue: T) -> Unit): Flow<T>
Delegates.observable
wasyl
11/25/2021, 2:38 PMrunningFold
or runningReduce
?Chris Fillmore
11/25/2021, 2:38 PMephemient
11/25/2021, 5:16 PMfun <T> Flow<T>.zipWithNext(): Flow<Pair<T, T>>
fun <T, R> Flow<T>.zipWithNext(action: suspend FlowCollector<R>.(oldValue: T, newValue: T) -> Unit): Flow<R>
or a modification of distinctUntilChangedBy
,
fun <T> Flow<T>.distinctUntilChangedWith(predicate: (T, T) -> Boolean): Flow<T>
to be proposed as additions to FlowChris Fillmore
11/25/2021, 5:29 PMfun <T> Flow<T>.onChange(action: suspend (oldValue: T, newValue: T) -> Unit): Flow<T> {
return runningReduce { old, new ->
action(old, new)
new
}
}
onChange
just because in my particular case I’m dealing with state changes in a StateFlow
, but another name might be more suitable to a general purpose Flow