Skip to content

handle error with partial function  #444

@prophe05

Description

@prophe05

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])

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions