<@U2E974ELT>, How would you implement `Consumable&...
# coroutines
j
@elizarov, How would you implement
Consumable<E>.first()
for the
Consumable
interface you propose? https://github.com/Kotlin/kotlinx.coroutines/pull/274#issuecomment-373393257
(Your proposition is very interesting, I'm trying to understand the implications)
e
When you
consumeEach { ... }
and you don’t need any more items you just do
throw CancellationException
(or some shared instance there of). That way you cancel the upstream producer.
We can even create a separate exception type to pull the resulting value for short-circuiting terminal opertation all the way up the stack. It is all just crazy idea that needs to be worked out.
j
Ok, thanks for the answer. I figured out how to achieve it by throwing an exception. However, it makes operator writing a bit harder than it currently is. I know it's just a recent crazy idea, but thank you very much for thinking and working on this. This will be very useful.