Jorge Bo
08/25/2022, 8:53 PMoverride suspend fun invoke(command: Command): Either<BusinessError, Unit> =
either {
val responseOne = serviceOne.call(command.data.first).bind()
val responseTwo = serviceTwo.call(command.data.second).bind()
if (responseOne.amount > responseTwo.amount) {
serviceThree.call()
}
}
Emil Kantis
08/25/2022, 9:05 PM@Deprecated("$deprecatedInFavorOfEagerEffectScope\nThis object introduces dangerous behavior and will be removed in the next version: <https://github.com/arrow-kt/arrow/issues/2547>")
I think you should do something like:
override suspend fun invoke(command: Command): Either<BusinessError, Unit> =
either {
val responseOne = serviceOne.call(command.data.first)
val responseTwo = serviceTwo.call(command.data.second)
when {
responseOne is Either.Right && responseTwo is Either.Right -> if (responseOne.value.amount > responseTwo.value.amount) {
serviceThree.call()
},
// handle remaining cases, where responses one, or two, or both fail
}
raulraja
08/25/2022, 9:59 PMbind
is deprecated in the computation
package but not on the continuations
package. Semantically though the way the code is written won't leverage that the second call may be performed in parallelraulraja
08/25/2022, 10:00 PMparZip
and take advantage we can perform effects inside either
and go async if needed.Jorge Bo
08/26/2022, 11:21 PMraulraja
08/26/2022, 11:29 PMF<A> -> A
it's possible in a non blocking way and we take advantage of suspend
to implement that.
There is more info around this here https://arrow-kt.io/docs/effects/io/ and feel free to ask here any other questions. Essentially continuations can model all monads and with continuations you can achieve F<A> -> A
which we call bind
, with bind you can remove the need for flatMap, map and others.raulraja
08/26/2022, 11:33 PMshift
https://arrow-kt.io/docs/apidocs/arrow-core/arrow.core.continuations/-effect/