> I am confused why use onEach though
ā¢
flow.onEach { doStuff(it) }.collect()
is equivalent to
flow.collect { doStuff(it) }
ā¢
flow.launchIn(scope)
is equivalent to
scope.launch { flow.collect() }
So... if you want to use
launchIn
, you kind of have to go with
onEach
, because you don't control the
collect()
call anymore (you can't pass a lambda to it). I do tend to prefer
scope.launch { flow.collect { ... } }
in general, but I don't have a very strong opinion on this, I guess it's a matter of style.
> I thought all of the "on*" operators were side-effecty
Well
updateUI(event)
seems quite side-effecty to me š It does seem to match what you expected here