arrow-fx / arrow.fx.typeclasses / Concurrent / parMapN

parMapN

open fun <A, B, C> parMapN(ctx: CoroutineContext, fa: Kind<F, A>, fb: Kind<F, B>, f: (Tuple2<A, B>) -> C): Kind<F, C>

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

import arrow.Kind
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, String> {
  //sampleStart
    val result = parMapN(
      Dispatchers.Default,
      effect { "First one is on ${Thread.currentThread().name}" },
      effect { "Second one is on ${Thread.currentThread().name}" }
    ) { (a, b) ->
      "$a\n$b"
    }
  //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

f - function to map/combine value A and B

Return F with the result of function f.

See Also

racePair

open fun <A, B, C> CoroutineContext.~~parMapN~~(fa: Kind<F, A>, fb: Kind<F, B>, f: (A, B) -> C): Kind<F, C> Deprecated: This API is not consistent with others within Arrow

open fun <A, B, C, D> CoroutineContext.~~parMapN~~(fa: Kind<F, A>, fb: Kind<F, B>, fc: Kind<F, C>, f: (A, B, C) -> D): Kind<F, D> Deprecated: This API is not consistent with others within Arrow

open fun <A, B, C, D, E> CoroutineContext.~~parMapN~~(fa: Kind<F, A>, fb: Kind<F, B>, fc: Kind<F, C>, fd: Kind<F, D>, f: (A, B, C, D) -> E): Kind<F, E> Deprecated: This API is not consistent with others within Arrow

open fun <A, B, C, D, E, G> CoroutineContext.~~parMapN~~(fa: Kind<F, A>, fb: Kind<F, B>, fc: Kind<F, C>, fd: Kind<F, D>, fe: Kind<F, E>, f: (A, B, C, D, E) -> G): Kind<F, G> Deprecated: This API is not consistent with others within Arrow

open fun <A, B, C, D, E, G, H> CoroutineContext.~~parMapN~~(fa: Kind<F, A>, fb: Kind<F, B>, fc: Kind<F, C>, fd: Kind<F, D>, fe: Kind<F, E>, fg: Kind<F, G>, f: (A, B, C, D, E, G) -> H): Kind<F, H> Deprecated: This API is not consistent with others within Arrow

open fun <A, B, C, D, E, G, H, I> CoroutineContext.~~parMapN~~(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>, f: (A, B, C, D, E, G, H) -> I): Kind<F, I> Deprecated: This API is not consistent with others within Arrow

open fun <A, B, C, D, E, G, H, I, J> CoroutineContext.~~parMapN~~(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>, f: (A, B, C, D, E, G, H, I) -> J): Kind<F, J> Deprecated: This API is not consistent with others within Arrow

open fun <A, B, C, D, E, G, H, I, J, K> CoroutineContext.~~parMapN~~(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>, f: (A, B, C, D, E, G, H, I, J) -> K): Kind<F, K> Deprecated: This API is not consistent with others within Arrow

open fun <A, B, C, D> parMapN(ctx: CoroutineContext, fa: Kind<F, A>, fb: Kind<F, B>, fc: Kind<F, C>, f: (Tuple3<A, B, C>) -> D): Kind<F, D> open fun <A, B, C, D, E> parMapN(ctx: CoroutineContext, fa: Kind<F, A>, fb: Kind<F, B>, fc: Kind<F, C>, fd: Kind<F, D>, f: (Tuple4<A, B, C, D>) -> E): Kind<F, E> open fun <A, B, C, D, E, G> parMapN(ctx: CoroutineContext, fa: Kind<F, A>, fb: Kind<F, B>, fc: Kind<F, C>, fd: Kind<F, D>, fe: Kind<F, E>, f: (Tuple5<A, B, C, D, E>) -> G): Kind<F, G> open fun <A, B, C, D, E, G, H> Concurrent<F>.parMapN(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>, f: (Tuple6<A, B, C, D, E, G>) -> H): Kind<F, H> open fun <F, A, B, C, D, E, G, H, I> Concurrent<F>.parMapN(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>, f: (Tuple7<A, B, C, D, E, G, H>) -> I): Kind<F, I> open fun <A, B, C, D, E, G, H, I, J> parMapN(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>, f: (Tuple8<A, B, C, D, E, G, H, I>) -> J): Kind<F, J> open fun <A, B, C, D, E, G, H, I, J, K> parMapN(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>, f: (Tuple9<A, B, C, D, E, G, H, I, J>) -> K): Kind<F, K>

See Also

parMapN

Do you like Arrow?

Arrow Org
<