Also, is there any alternative?
# coroutines
l
Also, is there any alternative?
e
Copy code
fun <T> ReceiveChannel<T>.onEach(block: (T) -> Unit): ReceiveChannel<T> =
    produce(onCompletion = consumes()) {
        for (it in this@onEach) {
            block(it)
            send(it)
        }
    }
l
That doesn't explain my previous question: Why it's not there? Should I submit a PR?
e
TooManyChannelsException. We’d like to redo all existing operators via cold streams first, then go on to expand repertoire of operators.
It’s kind of a waste to simply move elements between two channels, all for the pleasure of peeking at them via
onEach
.
l
I see. My small use case was scanning for a Bluetooth Low Energy device, expecting only one close by, and showing meaningful errors if it's not close enough, or more than one device is close. It was so complex adding a few other requirements that I finally gave up doing the complex filtering while the channel is receiving values, and just cancel the channel after a short duration, to then work on a list. I'll see if I can improve it to fail faster by using the new
broadcast()
function, and having one subscription channel per requirement.