Skip to content

Instantly share code, notes, and snippets.

@clojj
Created Aug 8, 2020
Embed
What would you like to do?
parallel map in Kotlin
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