//arrow-fx-coroutines/arrow.fx.coroutines/parMapUnordered

parMapUnordered

common inline fun <A, B> <[A](par-map-unordered.html)>.[parMapUnordered](par-map-unordered.html)(concurrency: [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html) = DEFAULT_CONCURRENCY, crossinline transform: suspend ([A](par-map-unordered.html)) -> [B](par-map-unordered.html)): <[B](par-map-unordered.html)>

Like map, but will evaluate effects in parallel, emitting the results downstream. The number of concurrent effects is limited by concurrency.

See parMap if retaining the original order of the stream is required.

import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.flow.toList
import kotlinx.coroutines.flow.collect
import arrow.fx.coroutines.parMapUnordered

//sampleStart
suspend fun main(): Unit {
  flowOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
    .parMapUnordered { a ->
      delay(100)
      a
    }.toList() // [3, 5, 4, 6, 2, 8, 7, 1, 9, 10]
}
//sampleEnd

Do you like Arrow?

Arrow Org
<