https://kotlinlang.org logo
#arrow-contributors
Title
# arrow-contributors
s

Satyam Agarwal

09/13/2020, 8:49 PM
I just made an extension function to replace it locally.
Copy code
inline fun <reified A, reified B> Either<Throwable, A>.product(f: () -> Either<Throwable, B>): Either<Throwable, Tuple2<A, B>> {
    return this.flatMap { a -> f().map { b -> a toT b } }
}
r

raulraja

09/13/2020, 9:17 PM
is this coming from an imported extension?
s

Satyam Agarwal

09/13/2020, 9:27 PM
you mean the error ? then yes, the
mproduct
is imported from
arrow.core.extensions.either.monad.mproduct
Copy code
implementation("io.arrow-kt:arrow-core-data:$arrowKtVersion")
    implementation("io.arrow-kt:arrow-core:$arrowKtVersion")
    implementation("io.arrow-kt:arrow-fx-coroutines:$arrowKtVersion")
    implementation("io.arrow-kt:arrow-fx-kotlinx-coroutines:$arrowKtVersion")
    implementation("io.arrow-kt:arrow-fx:$arrowKtVersion")
are dependencies I am pulling atm
i will remove
arrow-fx
and
arrow-fx-kotlinx-coroutines
once I have removed IO completely from project .
r

raulraja

09/13/2020, 10:51 PM
We are debating if those methods are useful since in suspension we have not found a use case for it that can't be done in place with easier syntax. Do you have a small example on how you are using mproduct ? I'd like to explore and see if that and others are worth keeping around for 1.0
s

Satyam Agarwal

09/13/2020, 11:15 PM
this is a pattern I do for all my ktor routers
Copy code
ParametersValidator
            .validateId(id)
            .toEither()
            .mproduct { tokenValidator.validateRequest(authorization) }
and then I use the destructured tuple as input to the service layer
Also
Either.fx { }
is deprecated, yet it is used the migration readme, and arrow website.
Copy code
@Deprecated("Fx blocks are now named based on each datatype, please use `either { }` instead",
  replaceWith = ReplaceWith("either.eager<L, R>(c)"))
fun <L, R> Either.Companion.fx(c: suspend MonadSyntax<EitherPartialOf<L>>.() -> R): Either<L, R> =
  Either.monad<L>().fx.monad(c).fix()

`
alternative given in
either.eager
which gives compilation error :
Copy code
Restricted suspending functions can only invoke member or extension suspending functions on their restricted coroutine scope
tried just
either { }
as well, thats same too.
I understand
Either.fx
is much better, but I don’t know why, I just love chaining methods, using extra syntax like map, flatmap, mproducts. 😅
31 Views