Skip to content
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

handle error with partial function #444

Open
prophe05 opened this issue Sep 2, 2022 · 0 comments
Open

handle error with partial function #444

prophe05 opened this issue Sep 2, 2022 · 0 comments

Comments

@prophe05
Copy link

prophe05 commented Sep 2, 2022

It would be nice to add to Handle methods that takes PartialFunction something like ApplicativeError has (recover and recoverWith). For all unmatched cases raise an exception with ApplicativeError, something like:

def handlePartially[A](fa: F[A])(pf: PartialFunction[E, A])(implicit ap: ApplicativeError[F, Throwable]): F[A] =
 handleWith[A](fa)(e => pf.andThen(applicative.pure[A](_)).applyOrElse[E, F[A]](e, me => ap.raiseError(new MatchError(me))))

And one step further, it would be super awesome if it would be possible to do like:
some_code.handlePartiallyWith[NarrowError](_.asLeft[Unit].pure[F])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant