https://kotlinlang.org logo
#coroutines
Title
# coroutines
d

deviant

09/18/2017, 3:25 PM
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

jmfayard

09/18/2017, 3:35 PM
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

deviant

09/18/2017, 3:37 PM
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

elizarov

09/18/2017, 4:03 PM
See this PR, it has a work-in-progress code around that and discussion https://github.com/Kotlin/kotlinx.coroutines/pull/88
👍 1
12 Views