Skip to content

Instantly share code, notes, and snippets.

@martinbeentjes
Created November 7, 2019 08:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save martinbeentjes/5778d8047a13c8e759dcf7e6c90d4715 to your computer and use it in GitHub Desktop.
Save martinbeentjes/5778d8047a13c8e759dcf7e6c90d4715 to your computer and use it in GitHub Desktop.
execute .map in parallel
import kotlinx.coroutines.async
import kotlinx.coroutines.awaitAll
import kotlinx.coroutines.coroutineScope
// Run in parallel
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