All Downloads are FREE. Search and download functionalities are using the official Maven repository.

utilities.parallelCollectionOperations.kt Maven / Gradle / Ivy

Go to download

Dokka is an API documentation engine for Kotlin and Java, performing the same function as Javadoc for Java

There is a newer version: 2.0.0
Show newest version
package org.jetbrains.dokka.utilities

import kotlinx.coroutines.async
import kotlinx.coroutines.awaitAll
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.launch
import org.jetbrains.dokka.InternalDokkaApi

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

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

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