arrow-fx-coroutines / arrow.fx.coroutines / parTupledN

parTupledN

suspend inline fun <A, B> ~~parTupledN~~(crossinline fa: suspend () -> A, crossinline fb: suspend () -> B): Pair<A, B> Deprecated: Use parZip instead

Runs fa, fb in parallel on Dispatchers.Default and combines their results into Pair.

import arrow.fx.coroutines.*

suspend fun main(): Unit {
  //sampleStart
  val (a, b) = parTupledN(
    { "First one is on ${Thread.currentThread().name}" },
    { "Second one is on ${Thread.currentThread().name}" }
  )
  //sampleEnd
 println("$a\n$b")
}

Parameters

fa - value to parallel map

fb - value to parallel map

See Also

parTupledN

suspend inline fun <A, B> ~~parTupledN~~(ctx: CoroutineContext = EmptyCoroutineContext, crossinline fa: suspend () -> A, crossinline fb: suspend () -> B): Pair<A, B> Deprecated: Use parZip instead

Runs fa, fb in parallel on ctx and combines their results into a Pair

Coroutine context is inherited from a CoroutineScope, additional context elements can be specified with ctx argument. If the combined context does not have any dispatcher nor any other ContinuationInterceptor, then Dispatchers.Default is used. WARNING If the combined context has a single threaded ContinuationInterceptor, this function will not run fa, fb in parallel.

import arrow.fx.coroutines.*
import kotlinx.coroutines.Dispatchers

suspend fun main(): Unit {
  //sampleStart
  val (a, b) = parTupledN(
    Dispatchers.IO,
    { "First one is on ${Thread.currentThread().name}" },
    { "Second one is on ${Thread.currentThread().name}" }
  )
  //sampleEnd
 println("$a\n$b")
}

Parameters

fa - value to parallel map

fb - value to parallel map

See Also

parTupledN

suspend inline fun <A, B, C> ~~parTupledN~~(crossinline fa: suspend () -> A, crossinline fb: suspend () -> B, crossinline fc: suspend () -> C): Triple<A, B, C> Deprecated: Use parZip instead

Runs fa, fb, fc in parallel on Dispatchers.Default and combines their results into Triple.

import arrow.fx.coroutines.*

suspend fun main(): Unit {
  //sampleStart
  val (a, b, c) = parTupledN(
    { "First one is on ${Thread.currentThread().name}" },
    { "Second one is on ${Thread.currentThread().name}" },
    { "Third one is on ${Thread.currentThread().name}" }
  )
  //sampleEnd
 println("$a\n$b\n$c")
}

Parameters

fa - value to parallel map

fb - value to parallel map

fc - value to parallel map

See Also

parMapN

suspend inline fun <A, B, C> ~~parTupledN~~(ctx: CoroutineContext = EmptyCoroutineContext, crossinline fa: suspend () -> A, crossinline fb: suspend () -> B, crossinline fc: suspend () -> C): Triple<A, B, C> Deprecated: Use parZip instead

Runs fa, fb, fc in parallel on ctx and combines their results using the provided function.

Coroutine context is inherited from a CoroutineScope, additional context elements can be specified with ctx argument. If the combined context does not have any dispatcher nor any other ContinuationInterceptor, then Dispatchers.Default is used. WARNING If the combined context has a single threaded ContinuationInterceptor, this function will not run fa, fb & fc in parallel.

import arrow.fx.coroutines.*
import kotlinx.coroutines.Dispatchers

suspend fun main(): Unit {
  //sampleStart
  val (a, b, c) = parTupledN(
    Dispatchers.IO,
    { "First one is on ${Thread.currentThread().name}" },
    { "Second one is on ${Thread.currentThread().name}" },
    { "Third one is on ${Thread.currentThread().name}" }
  )
  //sampleEnd
 println("$a\n$b\n$c")
}

Parameters

fa - value to parallel map

fb - value to parallel map

fc - value to parallel map

See Also

parTupledN

Do you like Arrow?

Arrow Org
<