Created
November 7, 2019 08:18
-
-
Save martinbeentjes/5778d8047a13c8e759dcf7e6c90d4715 to your computer and use it in GitHub Desktop.
execute .map in parallel
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.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