parallelMapIndexed

suspend fun <T, R> Iterable<T>.parallelMapIndexed(concurrency: Int = Int.MAX_VALUE, transform: suspend (index: Int, element: T) -> R): List<R>

Transforms every element with its index concurrently and returns the results in the original order.

At most concurrency transforms run at the same time, limited by a Semaphore. The first failing transform cancels the remaining work and its failure is rethrown to the caller.

Cancellation: cancelling the calling coroutine cancels every in-flight transform before rethrowing.

Parameters

concurrency

the maximum number of concurrent transforms, at least 1.

Throws