-
Notifications
You must be signed in to change notification settings - Fork 66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add recover either #506
base: main
Are you sure you want to change the base?
Add recover either #506
Conversation
Thank you for your contribution! However, let me chime in and share my thoughts about some of the PR details please.
Note that I cannot find a simple replacement for |
Thank you @satorg for the detailed review!
You are right! Updated the PR
Right, I added it for completeness mainly - the true need was just
Didn't notice that - you are right!
val ioa: IO[Unit] = ???
ioa.recoverAsLeft {
case ex: MyLogicalFailure => ex
}
// or when you have to lift to Either only some errors and map them basically
// In this case the errors not mapped will raise an exception and will be treated as 500 ( internal server error ) - the others // are properly treated with different error codes
ioa.recoverAsLeft {
case ex: MyLogicalFailure => HttpError(400, ex.getMessage)
} |
def recoverEither[E, L](pf: PartialFunction[E, Either[L, A]])(implicit F: ApplicativeError[F, E]): F[Either[L, A]] = | ||
F.recover(mapAsRight[L])(pf) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When #508 is published, It can be used as a counterpart:
val fa: F[Unit] = ???
fa.attempt.leftFlatMapOrKeepIn(pf)
But if we take allocations into consideration, it's probably better to have a distinct syntax for that.
Add methods to
AnyF
to recover errors toEither
where an instance ofMonadError[F]
is provided.New methods:
as
or not