From ff6fc1af470fd706ae79eaee467065c18e561d63 Mon Sep 17 00:00:00 2001 From: Wojciech Urbanski Date: Sat, 26 Jan 2019 11:47:08 +0100 Subject: [PATCH] Changed parent of InvariantMonoidalTests to invariantSemigroupal and moved invariant associativity test to InvariantSemigroupalTests --- .../main/scala/cats/laws/InvariantMonoidalLaws.scala | 5 ----- .../scala/cats/laws/InvariantSemigroupalLaws.scala | 8 ++++++++ .../cats/laws/discipline/InvariantMonoidalTests.scala | 8 +++----- .../laws/discipline/InvariantSemigroupalTests.scala | 11 ++++++++--- 4 files changed, 19 insertions(+), 13 deletions(-) diff --git a/laws/src/main/scala/cats/laws/InvariantMonoidalLaws.scala b/laws/src/main/scala/cats/laws/InvariantMonoidalLaws.scala index ed7b19c8ae..58c82d4766 100644 --- a/laws/src/main/scala/cats/laws/InvariantMonoidalLaws.scala +++ b/laws/src/main/scala/cats/laws/InvariantMonoidalLaws.scala @@ -15,11 +15,6 @@ trait InvariantMonoidalLaws[F[_]] extends InvariantSemigroupalLaws[F] { def invariantMonoidalRightIdentity[A, B](fa: F[A]): IsEq[F[A]] = fa.product(F.unit).imap(_._1)(a => (a, ())) <-> fa - def invariantMonoidalAssociativity[A, B, C](fa: F[A], fb: F[B], fc: F[C]): IsEq[F[(A, (B, C))]] = - fa.product(fb.product(fc)) <-> fa - .product(fb) - .product(fc) - .imap { case ((a, b), c) => (a, (b, c)) } { case (a, (b, c)) => ((a, b), c) } } object InvariantMonoidalLaws { diff --git a/laws/src/main/scala/cats/laws/InvariantSemigroupalLaws.scala b/laws/src/main/scala/cats/laws/InvariantSemigroupalLaws.scala index f81d718ad1..b15a7cea91 100644 --- a/laws/src/main/scala/cats/laws/InvariantSemigroupalLaws.scala +++ b/laws/src/main/scala/cats/laws/InvariantSemigroupalLaws.scala @@ -6,8 +6,16 @@ package laws */ trait InvariantSemigroupalLaws[F[_]] extends InvariantLaws[F] with SemigroupalLaws[F] { implicit override def F: InvariantSemigroupal[F] + import cats.syntax.semigroupal._ + import cats.syntax.invariant._ + def invariantSemigroupalAssociativity[A, B, C](fa: F[A], fb: F[B], fc: F[C]): IsEq[F[(A, (B, C))]] = + fa.product(fb.product(fc)) <-> fa + .product(fb) + .product(fc) + .imap { case ((a, b), c) => (a, (b, c)) } { case (a, (b, c)) => ((a, b), c) } } + object InvariantSemigroupalLaws { def apply[F[_]](implicit ev: InvariantSemigroupal[F]): InvariantSemigroupalLaws[F] = new InvariantSemigroupalLaws[F] { def F: InvariantSemigroupal[F] = ev } diff --git a/laws/src/main/scala/cats/laws/discipline/InvariantMonoidalTests.scala b/laws/src/main/scala/cats/laws/discipline/InvariantMonoidalTests.scala index 2b956abf4a..5c1b7bad51 100644 --- a/laws/src/main/scala/cats/laws/discipline/InvariantMonoidalTests.scala +++ b/laws/src/main/scala/cats/laws/discipline/InvariantMonoidalTests.scala @@ -20,17 +20,15 @@ trait InvariantMonoidalTests[F[_]] extends InvariantSemigroupalTests[F] { EqFABC2: Eq[F[(A, B, C)]], iso: Isomorphisms[F], EqFA: Eq[F[A]], + EqFB: Eq[F[B]], EqFC: Eq[F[C]]): RuleSet = new RuleSet { val name = "invariantMonoidal" - val parents = Seq(invariant[A, B, C], semigroupal[A, B, C]) + val parents = Seq(invariantSemigroupal[A, B, C]) val bases = Seq.empty val props = Seq( "invariant monoidal left identity" -> forAll((fa: F[A]) => laws.invariantMonoidalLeftIdentity(fa)), - "invariant monoidal right identity" -> forAll((fa: F[A]) => laws.invariantMonoidalRightIdentity(fa)), - "invariant monoidal associativity" -> forAll( - (fa: F[A], fb: F[B], fc: F[C]) => laws.invariantMonoidalAssociativity(fa, fb, fc) - ) + "invariant monoidal right identity" -> forAll((fa: F[A]) => laws.invariantMonoidalRightIdentity(fa)) ) } } diff --git a/laws/src/main/scala/cats/laws/discipline/InvariantSemigroupalTests.scala b/laws/src/main/scala/cats/laws/discipline/InvariantSemigroupalTests.scala index d6a5318f8e..e74b50e18f 100644 --- a/laws/src/main/scala/cats/laws/discipline/InvariantSemigroupalTests.scala +++ b/laws/src/main/scala/cats/laws/discipline/InvariantSemigroupalTests.scala @@ -2,8 +2,8 @@ package cats package laws package discipline -import cats.InvariantSemigroupal import cats.laws.discipline.SemigroupalTests.Isomorphisms +import org.scalacheck.Prop.forAll import org.scalacheck.{Arbitrary, Cogen} trait InvariantSemigroupalTests[F[_]] extends InvariantTests[F] with SemigroupalTests[F] { @@ -19,12 +19,17 @@ trait InvariantSemigroupalTests[F[_]] extends InvariantTests[F] with Semigroupal EqFA: Eq[F[A]], EqFB: Eq[F[B]], EqFC: Eq[F[C]], - EqFABC: Eq[F[(A, B, C)]], + EqFABC: Eq[F[(A, (B, C))]], + EqFABC2: Eq[F[(A, B, C)]], iso: Isomorphisms[F]): RuleSet = new RuleSet { val name = "invariantSemigroupal" val parents = Seq(invariant[A, B, C], semigroupal[A, B, C]) val bases = Nil - val props = Nil + val props = Seq( + "invariant semigroupal associativity" -> forAll( + (fa: F[A], fb: F[B], fc: F[C]) => laws.invariantSemigroupalAssociativity(fa, fb, fc) + ) + ) } }