Hi, anyone knows why there's no `onEach` function ...
# coroutines
l
Hi, anyone knows why there's no
onEach
function for
ReceiveChannel
?
s
Cant you just iterate it?
Copy code
for (msg in channel) {
msg.stuff() 
}
l
I can, but it doesn't chain well with
filter
and other operations. I saw it would not be enough to satisfy my use case anyway, so I went with a simple
consumeEach
and additional collections for blacklisting part of the elements
w
Be careful with
consumeEach
since it will close the channel if the coroutine you’re reading from exits/is canceled
The hard part of an
onEach
may be composability, for instance you’d probably need it at the start of the chain, because it’ll end up being something like iterating on the channel, doing some action, then returning the item
Or returning a new channel that you then need to iterate over as well