|
1 | 1 | package cats
|
2 | 2 | package tests
|
3 | 3 |
|
4 |
| -import cats.Bifunctor |
5 |
| -import cats.data.EitherT |
6 |
| - |
| 4 | +import cats.data.{EitherT, State} |
7 | 5 | import cats.laws.discipline._
|
8 | 6 | import cats.laws.discipline.arbitrary._
|
9 | 7 | import cats.laws.discipline.SemigroupalTests.Isomorphisms
|
10 | 8 | import cats.kernel.laws.discipline.{EqTests, MonoidTests, OrderTests, PartialOrderTests, SemigroupTests}
|
| 9 | + |
11 | 10 | import scala.util.{Failure, Success, Try}
|
12 | 11 |
|
13 | 12 | class EitherTSuite extends CatsSuite {
|
@@ -541,6 +540,43 @@ class EitherTSuite extends CatsSuite {
|
541 | 540 | }
|
542 | 541 | }
|
543 | 542 |
|
| 543 | + test("semiflatTap does not change the return value") { |
| 544 | + type TestEffect[A] = State[List[Int], A] |
| 545 | + forAll { (eithert: EitherT[TestEffect, String, Int], f: Int => TestEffect[Int], initial: List[Int]) => |
| 546 | + eithert.semiflatTap(v => f(v)).value.runA(initial) should ===(eithert.value.runA(initial)) |
| 547 | + } |
| 548 | + } |
| 549 | + |
| 550 | + test("semiflatTap runs the effect") { |
| 551 | + type TestEffect[A] = State[List[Int], A] |
| 552 | + forAll { (eithert: EitherT[TestEffect, String, Int], f: Int => TestEffect[Int], initial: List[Int]) => |
| 553 | + eithert.semiflatTap(v => f(v)).value.runS(initial) should ===(eithert.semiflatMap(f).value.runS(initial)) |
| 554 | + } |
| 555 | + } |
| 556 | + |
| 557 | + test("leftSemiflatTap does not change the return value") { |
| 558 | + type TestEffect[A] = State[List[Int], A] |
| 559 | + forAll { (eithert: EitherT[TestEffect, String, Int], f: String => TestEffect[Int], initial: List[Int]) => |
| 560 | + eithert.leftSemiflatTap(v => f(v)).value.runA(initial) should ===(eithert.value.runA(initial)) |
| 561 | + } |
| 562 | + } |
| 563 | + |
| 564 | + test("leftSemiflatTap runs the effect") { |
| 565 | + type TestEffect[A] = State[List[Int], A] |
| 566 | + forAll { (eithert: EitherT[TestEffect, String, Int], f: String => TestEffect[Int], initial: List[Int]) => |
| 567 | + eithert.leftSemiflatTap(v => f(v)).value.runS(initial) should ===(eithert.leftSemiflatMap(f).value.runS(initial)) |
| 568 | + } |
| 569 | + } |
| 570 | + |
| 571 | + test("leftSemiflatTap consistent with swap and the semiflatTap") { |
| 572 | + type TestEffect[A] = State[List[Int], A] |
| 573 | + forAll { (eithert: EitherT[TestEffect, String, Int], f: String => TestEffect[Int], initial: List[Int]) => |
| 574 | + eithert.leftSemiflatTap(v => f(v)).value.runA(initial) should ===( |
| 575 | + eithert.swap.semiflatTap(v => f(v)).swap.value.runA(initial) |
| 576 | + ) |
| 577 | + } |
| 578 | + } |
| 579 | + |
544 | 580 | test("biSemiflatMap consistent with leftSemiflatMap and semiFlatmap") {
|
545 | 581 | forAll { (eithert: EitherT[List, String, Int], fa: String => List[Int], fb: Int => List[String]) =>
|
546 | 582 | eithert.biSemiflatMap(fa, fb) should ===(eithert.leftSemiflatMap(fa).semiflatMap(fb))
|
|
0 commit comments