I fetch some data from the server and forward it t...
# coroutines
s
I fetch some data from the server and forward it to via a Flow object. I need to do some accessory work based on the fetched data but I don't need to transform the data which remains as it is. It doesn't look like I would use
map
operator here. Where should I do this accessory work? In the repository before the values are emitted or in the UI where the data is delivered. Or if there is another operator that let's me do such accessory work.
w
If by accessory work you mean just side effects, there’s
.onEach {  }
operator which receives each item for processing
As for where — it really depends on what it is (is it more of a data-layer concern or UI). Also there’s a question if you need to do that work before item gets emitted (that’s what
onEach
does) or in parallel. And if in parallel, then whether cancelling the flow should cancel this accessory work 🙂
s
Got it. I suppose I have to use
collect
which is where I can do the accessory work and also push the data to the UI using the
LiveData
. Thanks.
👍 1