pakoito
04/10/2018, 10:25 AMgroostav
04/10/2018, 8:39 PMChannel
, where
val x = produce { send(3), send(4), send(5) }
val mapped = x.map { it * 2 }
would provide a channel containing 6
, 8
and 10
, while preserving the suspend (and close) semantics
meaning, I believe, its safely implemented with
inline fun <T, R> Channel<T>.map(
crossinline transform: (T) -> R
): Channel<R> = produce {
for(message in this){
val next = recieve()
//try-catch might be a big problem here.
send(transform(next))
}
send(transform(recieve()))
}
flatMap
get a little confusing herepakoito
04/10/2018, 8:48 PMgroostav
04/11/2018, 6:14 AMproduce
Uncaught exceptions in this coroutine close the channel with this exception as a cause and the resulting channel becomes failed, so that any attempt to receive from such a channel throws exception.
Channel.map
kingsley
04/11/2018, 8:01 AM