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.
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
AnyFto recover errors toEitherwhere an instance ofMonadError[F]is provided.New methods:
asor not