Udith
08/15/2024, 2:39 PMcatch
operator. But the lambda should get error as well the previous item
This is what i have at the moment 👇. I need help to make it functional.Udith
08/15/2024, 2:40 PMpublic fun <T> Flow<T>.catchWithReferenceToLastValue(
action: suspend FlowCollector<T>.(item: T?, cause: Throwable) -> Unit
): Flow<T> = flow {
var previousValue: T? = null
collect { value ->
previousValue = value
emit(value)
catch { cause -> action(previousValue, cause) }
}
}
Udith
08/15/2024, 2:50 PMpublic fun <T> Flow<T>.catchWithReferenceToLastValue(
action: suspend FlowCollector<T>.(item: T?, cause: Throwable) -> Unit
): Flow<T> {
var previousValue: T? = null
return flow {
collect { value ->
previousValue = value
emit(value)
}
}.catch { cause -> action(previousValue, cause) }
}