Skip to content

Commit

Permalink
added to (#2780)
Browse files Browse the repository at this point in the history
  • Loading branch information
kailuowang authored Apr 9, 2019
1 parent ca425bf commit d3b6ee7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions core/src/main/scala/cats/data/EitherT.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions tests/src/test/scala/cats/tests/EitherTSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit d3b6ee7

Please sign in to comment.