-
-
Save kostapc/77b3e7d80b6183c022f480bcec712b4d 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