just curious: what is the best way to convert `Cha...
# coroutines
d
just curious: what is the best way to convert
Channel
into
Sequence
? is it possible? something like that
Copy code
produce<Int>{
 send(1)
 send(2)
 send(3)
}
.asSequence()  // some suspendable helper?
.filter {it==1}
j
That does not make sense to me. At which point would your function go back from suspension? After all suspending functions are completed, possibly forever ? The reason for choosing a sequence over a list is when you want it to be lazy. But your producer is already lazy. What you probably want to do is apply a filter operator on top of the channel
d
yes. but there is no
filter
,
map
etc for the Channel
i tried this:
Copy code
buildSequence {
        for (item in channel) {
            yield(item)
        }
    }
but it doen't allow me to iterate on channel inside of builder
e
See this PR, it has a work-in-progress code around that and discussion https://github.com/Kotlin/kotlinx.coroutines/pull/88
👍 1