Skip to content

Commit 5d74ad5

Browse files
committed
Add tests for leftMapOrKeep & leftFlatMapOrKeep
1 parent 03c055e commit 5d74ad5

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

tests/shared/src/test/scala/cats/tests/EitherSuite.scala

+19
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,25 @@ class EitherSuite extends CatsSuite {
415415
}
416416
}
417417

418+
test("leftFlatMapOrKeep consistent with leftMapOrKeep") {
419+
forAll { (either: Either[String, Int], pf: PartialFunction[String, String]) =>
420+
val liftedPF: PartialFunction[String, Either[String, Int]] = { case a =>
421+
Either.left[String, Int](pf.applyOrElse(a, identity[String]))
422+
}
423+
assert(either.leftFlatMapOrKeep(liftedPF) === either.leftMapOrKeep(pf))
424+
}
425+
}
426+
427+
test("leftFlatMapOrKeep consistent with swap and then flatMapOrKeep") {
428+
import cats.syntax.monad._
429+
430+
forAll { (either: Either[String, Int], pf: PartialFunction[String, Either[String, Int]]) =>
431+
assert(either.leftFlatMapOrKeep(pf) === either.swap.flatMapOrKeep { case a =>
432+
pf.applyOrElse(a, (_: String) => either).swap
433+
}.swap)
434+
}
435+
}
436+
418437
test("raiseWhen raises when true") {
419438
val result = Either.raiseWhen(true)("ok")
420439
assert(result === Left("ok"))

0 commit comments

Comments
 (0)