For a channel what is the opposite of a flatMap, i...
# coroutines
l
For a channel what is the opposite of a flatMap, in other words how to take a channel of some array and start sending the values individually?
b
Are you saying
Channel<Array<T>>
and flatten it to
Channel<T>
?
l
yes exactly
d
I edited the example from https://kotlinlang.org/docs/reference/coroutines/channels.html#pipelines
Copy code
fun <T> CoroutineScope.flatten(channel: ReceiveChannel<Array<T>>): ReceiveChannel<T> = produce {
    for (items in channel) {
        for(item in items) send(item)
    }
}
However there could be something already that i don't know...
l
cool thanks!
b
If you're going to do other operators, you should consider using a
Flow
Copy code
val myChannel = channel
    .consumeAsFlow()
    .flatMapConcat { it.asFlow() }
    .filter { ... }
    .map { ... }
    .produceIn(myScope)
d