aballano
02/04/2022, 4:29 PMonEachLatest sort of 🤔 Sharing here for feedback or in case I’m missing something 😬
@ExperimentalCoroutinesApi
public fun <T> Flow<T>.onEachLatest(action: suspend (T) -> Unit): Flow<T> = transformLatest { value ->
action(value)
return@transformLatest emit(value)
}
the only real difference with onEach is the transform -> transformLatest but I guess that should work, right?Nick Allen
02/04/2022, 4:49 PMmapLatest { action(it); it }
Avoid side effects unless you are calling a terminal operator. If a Flow is collected twice, your side effects will happen twice.
If you are calling a terminal operator, then consider just using collectLatest and do your side effect there.aballano
02/04/2022, 5:06 PM