can we get something like `ChannelIterable` that h...
# coroutines
j
can we get something like
ChannelIterable
that has
fun iterator(): ChannelIterator<T>
?
o
And what’s
ChannelIterator
?
j
that's already in the coroutine library. It's basically
Iterator
but with
suspend
on the functions
o
Ah, you mean just extract another interface from
ReceiveChannel
? Why?
j
So that I can implement it on custom types and you can do
for (value in myType)
instead of
for (value in myType.iterator())
o
Is it polymorphic or something? You don’t need an
*Iterable
interface for this, just an
operator fun
with compatible signature
j
Oh cool I guess that makes sense. I assumed because of the suspension stuff that wouldn't work
Actually, I think one of the reasons I was looking for the interface was access to the context...
I don't know. I need to look later and try with what you said. I stepped away from my computer and am probably saying all the wrong things now.
o
Just copy
iterator
signature from the interface and implement it, should just work without explicit call to
iterator()
in a
for
loop
j
Ok after more thought and less typing on a small screen what I want is impossible because I don't have a way to grab the coroutine context from the enclosing scope
Basically given a class I have no way of capturing the enclosing context when you call the method
I think I need multi-receiver extension functions to be able to capture the CoroutineScope off which I can pull the context and then the instance of my object. And that means you still need to call a method and can't just for-each it 😞
o
@elizarov use case for that magic context property?
e
Yes. There are lots of them. See here: https://youtrack.jetbrains.com/issue/KT-17609
👍 2