From d571771ef5c8b692b9b015263e3b3d0f26c49298 Mon Sep 17 00:00:00 2001 From: Luka Jacobowitz Date: Wed, 30 Aug 2017 17:31:25 +0200 Subject: [PATCH] Add sequential roundtrip law --- laws/src/main/scala/cats/laws/ParallelLaws.scala | 3 +++ .../scala/cats/laws/discipline/ParallelTests.scala | 12 +++++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/laws/src/main/scala/cats/laws/ParallelLaws.scala b/laws/src/main/scala/cats/laws/ParallelLaws.scala index ad79ac05e68..dfaa894d01c 100644 --- a/laws/src/main/scala/cats/laws/ParallelLaws.scala +++ b/laws/src/main/scala/cats/laws/ParallelLaws.scala @@ -11,6 +11,9 @@ trait ParallelLaws[M[_], F[_]] { def parallelRoundTrip[A](ma: M[A]): IsEq[M[A]] = P.sequential(monadM)(P.parallel(monadM)(ma)) <-> ma + + def sequentialRoundTrip[A](fa: F[A]): IsEq[F[A]] = + P.parallel(monadM)(P.sequential(monadM)(fa)) <-> fa } object ParallelLaws { diff --git a/laws/src/main/scala/cats/laws/discipline/ParallelTests.scala b/laws/src/main/scala/cats/laws/discipline/ParallelTests.scala index 8fc2af69305..0d269597ffb 100644 --- a/laws/src/main/scala/cats/laws/discipline/ParallelTests.scala +++ b/laws/src/main/scala/cats/laws/discipline/ParallelTests.scala @@ -9,11 +9,13 @@ import org.typelevel.discipline.Laws trait ParallelTests[M[_], F[_], A] extends Laws { def laws: ParallelLaws[M, F] - def parallel(implicit ArbM: Arbitrary[M[A]], EqMa: Eq[M[A]]): RuleSet = new DefaultRuleSet( - "parallel", - None, - "parallel round trip" -> forAll((ma: M[A]) => laws.parallelRoundTrip(ma)) - ) + def parallel(implicit ArbM: Arbitrary[M[A]], EqMa: Eq[M[A]], ArbF: Arbitrary[F[A]], EqFa: Eq[F[A]]): RuleSet = + new DefaultRuleSet( + "parallel", + None, + "parallel round trip" -> forAll((ma: M[A]) => laws.parallelRoundTrip(ma)), + "sequential round trip" -> forAll((fa: F[A]) => laws.sequentialRoundTrip(fa)) + ) } object ParallelTests {