Skip to content

Instantly share code, notes, and snippets.

Created Aug 8, 2020
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