Skip to content

Commit

Permalink
Merge pull request #3162 from travisbrown/topic/ugh-adapt-error
Browse files Browse the repository at this point in the history
Add adaptError override to MonadError
  • Loading branch information
travisbrown authored Nov 21, 2019
2 parents 55c48a8 + 7043b05 commit 44bea32
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions core/src/main/scala/cats/MonadError.scala
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ trait MonadError[F[_], E] extends ApplicativeError[F, E] with Monad[F] {
*/
def redeemWith[A, B](fa: F[A])(recover: E => F[B], bind: A => F[B]): F[B] =
flatMap(attempt(fa))(_.fold(recover, bind))

override def adaptError[A](fa: F[A])(pf: PartialFunction[E, E]): F[A] =
recoverWith(fa)(pf.andThen(raiseError[A] _))
}

object MonadError {
Expand Down

0 comments on commit 44bea32

Please sign in to comment.