dnowak
09/27/2021, 9:38 PM() -> Either<Failure, Result>
and
• (Failure) -> Error
to () -> Either<Error, Result
.
All I want to do is to “decorate” a function returning Either
with error mapping.simon.vergauwen
09/28/2021, 6:20 AMsimon.vergauwen
09/28/2021, 6:24 AMEither#redeemWith
takes:
• (Failure) -> Either<Error, B>
• (Result) -> Either<Error, B>
So with that you can apply the desired transformations.
val initial: () -> Either<Failure, Result> = TODO()
val error: (Failure) -> Error = TODO()
val success: () -> Either<Error, Result> = TODO()
val r: Either<Error, Result> =
initial()
.redeemWith({ fail: Failure ->
error(fail).left()
}, { _: Result ->
success()
})
dnowak
09/28/2021, 8:06 AMval initlial: () -> Either<Failure, Result> = TODO()
val mapError: (Failure) -> Error = TODO()
val mapped: () -> Either<Error, Result> = {
initial().mapLeft(::mapError)
}
dnowak
09/28/2021, 8:09 AMEither
val mapped = initial.mapLeft(::mapError)
simon.vergauwen
09/28/2021, 8:30 AMintial.andThen { it.mapLeft(::mapError) }
simon.vergauwen
09/28/2021, 8:30 AMandThen
is a function for composing functions with each other.dnowak
09/28/2021, 10:07 AM