Created
August 8, 2020 18:08
-
-
Save clojj/bf8f2ae5392a2be41e31b71259ef4c6f to your computer and use it in GitHub Desktop.
parallel map in Kotlin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import kotlinx.coroutines.async | |
import kotlinx.coroutines.runBlocking | |
import kotlinx.coroutines.coroutineScope | |
import kotlinx.coroutines.awaitAll | |
suspend fun <A, B> Iterable<A>.pmap(f: suspend (A) -> B): List<B> = coroutineScope { | |
map { async { f(it) } }.awaitAll() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment