|
|
@ -4,6 +4,7 @@ import kotlinx.coroutines.async |
|
|
|
import kotlinx.coroutines.awaitAll |
|
|
|
import kotlinx.coroutines.awaitAll |
|
|
|
import kotlinx.coroutines.coroutineScope |
|
|
|
import kotlinx.coroutines.coroutineScope |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// https://jivimberg.io/blog/2018/05/04/parallel-map-in-kotlin/ |
|
|
|
suspend fun <A, B> Iterable<A>.parallelMap(f: suspend (A) -> B): List<B> = coroutineScope { |
|
|
|
suspend fun <A, B> Iterable<A>.parallelMap(f: suspend (A) -> B): List<B> = coroutineScope { |
|
|
|
map { async { f(it) } }.awaitAll() |
|
|
|
map { async { f(it) } }.awaitAll() |
|
|
|
} |
|
|
|
} |