Marcin Gryszko
09/24/2020, 5:07 PMfun <F> Applicative<F>.combine(
fn1: () -> Kind<F, Any>,
fn2: () -> Kind<F, Any>
): Kind<F, Any> =
fn1().map2(fn2) { (a, b) ->
// do sth with a and b
}
With Arrow 0.11 I'm trying to pass effectful computations as suspend functions. I'm able to combine them using the either
companion:
suspend fun combine(
fn1: suspend () -> Either<Throwable, Any>,
fn2: suspend () -> Either<Throwable, Any>
): Either<F, Any> =
either {
val a = !fn1()
val b = !fn2()
// do sth with a and b
}
If I want to execute the effects concurrently with parMapN
, I'm not able to unwrap Either
values and work with them:
parMapN(fn1, fn2) { a, b ->
// Compile error: Suspension functions can be called only within coroutine body
either {
// same code as in the sequential example
}
}
Is there a way to combine parMapN
with Either comprehensions?raulraja
09/24/2020, 7:22 PMraulraja
09/24/2020, 7:23 PMMarcin Gryszko
09/24/2020, 7:24 PMparMapN
is not a suspend
function:
parMapN(fa: suspend () -> A, fb: suspend () -> B, f: (A, B) -> C)
Marcin Gryszko
09/24/2020, 7:25 PMarrow.fx.coroutines
raulraja
09/24/2020, 7:26 PMraulraja
09/24/2020, 7:27 PMMarcin Gryszko
09/24/2020, 8:04 PMeither {
parMapN(fn1, fn2) { a, b ->
val aUnwrapped = !a // Compile error: Suspension functions can be called only within coroutine body
}
}
Would it make sense to add a parMap
variant accepting a suspend
combining function:
parMapN(fa: suspend () -> A, fb: suspend () -> B, suspend f: (A, B) -> C)
raulraja
09/24/2020, 10:02 PMraulraja
09/24/2020, 10:04 PM