diff --git a/core/src/main/scala/cats/data/EitherT.scala b/core/src/main/scala/cats/data/EitherT.scala index eb7f3668a1..658cdd0f67 100644 --- a/core/src/main/scala/cats/data/EitherT.scala +++ b/core/src/main/scala/cats/data/EitherT.scala @@ -15,6 +15,8 @@ import cats.syntax.either._ final case class EitherT[F[_], A, B](value: F[Either[A, B]]) { def fold[C](fa: A => C, fb: B => C)(implicit F: Functor[F]): F[C] = F.map(value)(_.fold(fa, fb)) + def foldF[C](fa: A => F[C], fb: B => F[C])(implicit F: FlatMap[F]): F[C] = F.flatMap(value)(_.fold(fa, fb)) + def isLeft(implicit F: Functor[F]): F[Boolean] = F.map(value)(_.isLeft) def isRight(implicit F: Functor[F]): F[Boolean] = F.map(value)(_.isRight) diff --git a/tests/src/test/scala/cats/tests/EitherTSuite.scala b/tests/src/test/scala/cats/tests/EitherTSuite.scala index e5679b5afb..88ecf882bc 100644 --- a/tests/src/test/scala/cats/tests/EitherTSuite.scala +++ b/tests/src/test/scala/cats/tests/EitherTSuite.scala @@ -325,6 +325,12 @@ class EitherTSuite extends CatsSuite { } } + test("foldF with Id consistent with Either fold") { + forAll { (eithert: EitherT[Id, String, Int], f: String => Long, g: Int => Long) => + eithert.foldF(f, g) should ===(eithert.value.fold(f, g)) + } + } + test("valueOr with Id consistent with Either valueOr") { forAll { (eithert: EitherT[Id, String, Int], f: String => Int) => eithert.valueOr(f) should ===(eithert.value.valueOr(f))