Last active
January 9, 2020 11:37
-
-
Save slaypni/7bceb24118f6fc03f757ab01f1c1eb04 to your computer and use it in GitHub Desktop.
Parallel map for kotlin
This file contains hidden or 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.experimental.async | |
import kotlin.coroutines.experimental.CoroutineContext | |
suspend fun <T, R> Iterable<T>.pmap(context: CoroutineContext, transform: suspend (T) -> R): List<R> { | |
return this.map { | |
async(context) { | |
transform(it) | |
} | |
}.map { it.await() } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment