arrow-fx / arrow.fx.typeclasses / Concurrent / parTupledN

parTupledN

open fun <A, B> parTupledN(ctx: CoroutineContext, fa: Kind<F, A>, fb: Kind<F, B>): Kind<F, Tuple2<A, B>>

Map two tasks in parallel within a new F on ctx.

import arrow.Kind
import arrow.core.Tuple2
import arrow.fx.IO
import kotlinx.coroutines.Dispatchers
import arrow.fx.typeclasses.Concurrent
import arrow.fx.extensions.io.concurrent.concurrent
import arrow.fx.fix

fun main(args: Array<String>) {
  fun <F> Concurrent<F>.example(): Kind<F, Tuple2<String, String>> {
  //sampleStart
    val result = parTupledN(
      Dispatchers.Default,
      effect { "First one is on ${Thread.currentThread().name}" },
      effect { "Second one is on ${Thread.currentThread().name}" }
    )
  //sampleEnd
  return result
  }

  IO.concurrent().example().fix().unsafeRunSync().let(::println)
}

Parameters

ctx - CoroutineContext to execute the source F on.

fa - value to parallel map

fb - value to parallel map

Return F with the result of function fa and fb.

See Also

racePair

open fun <A, B, C> parTupledN(ctx: CoroutineContext, fa: Kind<F, A>, fb: Kind<F, B>, fc: Kind<F, C>): Kind<F, Tuple3<A, B, C>> open fun <A, B, C, D> parTupledN(ctx: CoroutineContext, fa: Kind<F, A>, fb: Kind<F, B>, fc: Kind<F, C>, fd: Kind<F, D>): Kind<F, Tuple4<A, B, C, D>> open fun <A, B, C, D, E> Concurrent<F>.parTupledN(ctx: CoroutineContext, fa: Kind<F, A>, fb: Kind<F, B>, fc: Kind<F, C>, fd: Kind<F, D>, fe: Kind<F, E>): Kind<F, Tuple5<A, B, C, D, E>> open fun <A, B, C, D, E, G> Concurrent<F>.parTupledN(ctx: CoroutineContext, fa: Kind<F, A>, fb: Kind<F, B>, fc: Kind<F, C>, fd: Kind<F, D>, fe: Kind<F, E>, fg: Kind<F, G>): Kind<F, Tuple6<A, B, C, D, E, G>> open fun <A, B, C, D, E, G, H> parTupledN(ctx: CoroutineContext, fa: Kind<F, A>, fb: Kind<F, B>, fc: Kind<F, C>, fd: Kind<F, D>, fe: Kind<F, E>, fg: Kind<F, G>, fh: Kind<F, H>): Kind<F, Tuple7<A, B, C, D, E, G, H>> open fun <A, B, C, D, E, G, H, I> parTupledN(ctx: CoroutineContext, fa: Kind<F, A>, fb: Kind<F, B>, fc: Kind<F, C>, fd: Kind<F, D>, fe: Kind<F, E>, fg: Kind<F, G>, fh: Kind<F, H>, fi: Kind<F, I>): Kind<F, Tuple8<A, B, C, D, E, G, H, I>> open fun <A, B, C, D, E, G, H, I, J> parTupledN(ctx: CoroutineContext, fa: Kind<F, A>, fb: Kind<F, B>, fc: Kind<F, C>, fd: Kind<F, D>, fe: Kind<F, E>, fg: Kind<F, G>, fh: Kind<F, H>, fi: Kind<F, I>, fj: Kind<F, J>): Kind<F, Tuple9<A, B, C, D, E, G, H, I, J>>

See Also

parMapN

Do you like Arrow?

Arrow Org
<