Skip to content

Commit 02e6c81

Browse files
committed
Simplified implementation of Channel.flatMap using toChannel function.
Fixes #205
1 parent 3e342e3 commit 02e6c81

File tree

1 file changed

+3
-6
lines changed
  • core/kotlinx-coroutines-core/src/main/kotlin/kotlinx/coroutines/experimental/channels

1 file changed

+3
-6
lines changed

core/kotlinx-coroutines-core/src/main/kotlin/kotlinx/coroutines/experimental/channels/Channels.kt

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@
1616

1717
package kotlinx.coroutines.experimental.channels
1818

19-
import kotlinx.coroutines.experimental.Unconfined
20-
import kotlinx.coroutines.experimental.runBlocking
21-
import kotlin.coroutines.experimental.CoroutineContext
19+
import kotlinx.coroutines.experimental.*
20+
import kotlin.coroutines.experimental.*
2221

2322
internal const val DEFAULT_CLOSE_MESSAGE = "Channel was closed"
2423

@@ -884,9 +883,7 @@ public suspend fun <E> ReceiveChannel<E>.toSet(): Set<E> =
884883
public fun <E, R> ReceiveChannel<E>.flatMap(context: CoroutineContext = Unconfined, transform: suspend (E) -> ReceiveChannel<R>): ReceiveChannel<R> =
885884
produce(context) {
886885
consumeEach {
887-
transform(it).consumeEach {
888-
send(it)
889-
}
886+
transform(it).toChannel(this)
890887
}
891888
}
892889

0 commit comments

Comments
 (0)