Skip to content

Commit

Permalink
Add ApplicativeError.redeem and MonadError.redeemWith
Browse files Browse the repository at this point in the history
  • Loading branch information
joan38 committed Oct 17, 2018
1 parent 191fae4 commit 3187dcf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions core/src/main/scala/cats/syntax/applicativeError.scala
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ final class ApplicativeErrorOps[F[_], E, A](val fa: F[A]) extends AnyVal {
def attemptT(implicit F: ApplicativeError[F, E]): EitherT[F, E, A] =
F.attemptT(fa)

def redeem[B](recover: E => B, map: A => B)(implicit F: ApplicativeError[F, E]): F[B] =
F.map(F.attempt(fa))(_.fold(recover, mapper))

def recover(pf: PartialFunction[E, A])(implicit F: ApplicativeError[F, E]): F[A] =
F.recover(fa)(pf)

Expand Down
3 changes: 3 additions & 0 deletions core/src/main/scala/cats/syntax/monadError.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ final class MonadErrorOps[F[_], E, A](val fa: F[A]) extends AnyVal {

def adaptError(pf: PartialFunction[E, E])(implicit F: MonadError[F, E]): F[A] =
F.adaptError(fa)(pf)

def redeemWith[B](recover: E => F[B], bind: A => F[B])(implicit F: MonadError[F, E]): F[B] =
F.flatMap(F.attempt(fa))(_.fold(recover, bind))
}

final class MonadErrorRethrowOps[F[_], E, A](val fea: F[Either[E, A]]) extends AnyVal {
Expand Down

0 comments on commit 3187dcf

Please sign in to comment.