Skip to content

Commit

Permalink
make sure that EitherT MonadError syntax works the old way
Browse files Browse the repository at this point in the history
  • Loading branch information
kailuowang committed Nov 14, 2017
1 parent aeff8a6 commit e970e94
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 45 deletions.
40 changes: 20 additions & 20 deletions core/src/main/scala/cats/data/EitherT.scala
Original file line number Diff line number Diff line change
Expand Up @@ -483,26 +483,6 @@ private[data] abstract class EitherTInstances1 extends EitherTInstances2 {
val F0: Traverse[F] = F
}

/** Monad error instance for recovering errors in F instead of
* the underlying Either.
*
* {{{
* scala> import cats.data.EitherT
* scala> import cats.MonadError
* scala> import cats.instances.option._
* scala> val noInt: Option[Either[String, Int]] = None
* scala> val et = EitherT[Option, String, Int](noInt)
* scala> val me = MonadError[EitherT[Option, String, ?], Unit]
* scala> me.recover(et) { case () => 1 }
* res0: cats.data.EitherT[Option,String,Int] = EitherT(Some(Right(1)))
* }}}
*/
implicit def catsDataMonadErrorFForEitherT[F[_], E, L](implicit FE0: MonadError[F, E]): MonadError[EitherT[F, L, ?], E] =
new EitherTMonadErrorF[F, E, L] { implicit val F = FE0 }
}

private[data] abstract class EitherTInstances2 extends EitherTInstances3 {

implicit def catsDataMonadErrorForEitherT[F[_], L](implicit F0: Monad[F]): MonadError[EitherT[F, L, ?], L] =
new EitherTMonadError[F, L] {
implicit val F = F0
Expand All @@ -512,6 +492,26 @@ private[data] abstract class EitherTInstances2 extends EitherTInstances3 {
override def ensureOr[A](fa: EitherT[F, L, A])(error: (A) => L)(predicate: (A) => Boolean): EitherT[F, L, A] =
fa.ensureOr(error)(predicate)(F)
}
}

private[data] abstract class EitherTInstances2 extends EitherTInstances3 {
/** Monad error instance for recovering errors in F instead of
* the underlying Either.
*
* {{{
* scala> import cats.data.EitherT
* scala> import cats.MonadError
* scala> import cats.instances.option._
* scala> val noInt: Option[Either[String, Int]] = None
* scala> val et = EitherT[Option, String, Int](noInt)
* scala> val me = MonadError[EitherT[Option, String, ?], Unit]
* scala> me.recover(et) { case () => 1 }
* res0: cats.data.EitherT[Option,String,Int] = EitherT(Some(Right(1)))
* }}}
*/
implicit def catsDataMonadErrorFForEitherT[F[_], E, L](implicit FE0: MonadError[F, E]): MonadError[EitherT[F, L, ?], E] =
new EitherTMonadErrorF[F, E, L] { implicit val F = FE0 }


implicit def catsDataSemigroupKForEitherT[F[_], L](implicit F0: Monad[F]): SemigroupK[EitherT[F, L, ?]] =
new EitherTSemigroupK[F, L] { implicit val F = F0 }
Expand Down
25 changes: 0 additions & 25 deletions tests/src/test/scala-2.11+/cats/tests/RegressionTests.scala

This file was deleted.

14 changes: 14 additions & 0 deletions tests/src/test/scala/cats/tests/RegressionSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,18 @@ class RegressionSuite extends CatsSuite {
checkAndResetCount(1)
}

test("#2022 EitherT syntax no long works the old way") {
import data._


EitherT.right[String](Option(1)).handleErrorWith((_: String) => EitherT.pure(2))

{
implicit val me = MonadError[EitherT[Option, String, ?], Unit]
EitherT.right[String](Option(1)).handleErrorWith((_: Unit) => EitherT.pure(2))
}


}

}

0 comments on commit e970e94

Please sign in to comment.