aboutsummaryrefslogtreecommitdiff
path: root/core/src/main/kotlin/utilities/parallelCollectionOperations.kt
blob: 35ad48fd3643031e1e96abf9877ee74e5ddce573 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
package org.jetbrains.dokka.utilities

import kotlinx.coroutines.*

suspend inline fun <A, B> Iterable<A>.parallelMap(crossinline f: suspend (A) -> B): List<B> = coroutineScope {
    map { async { f(it) } }.awaitAll()
}

suspend inline fun <A, B> Iterable<A>.parallelMapNotNull(crossinline f: suspend (A) -> B?): List<B> = coroutineScope {
    map { async { f(it) } }.awaitAll().filterNotNull()
}

suspend inline fun <A> Iterable<A>.parallelForEach(crossinline f: suspend (A) -> Unit): Unit = coroutineScope {
    forEach { launch { f(it) } }
}