From f486ae2a700ad5e463120c5b6d417eadc20c1063 Mon Sep 17 00:00:00 2001 From: Carlos Quiroz <3615303+cquiroz@users.noreply.github.com> Date: Sat, 10 Sep 2022 23:31:04 -0400 Subject: [PATCH 1/3] Don't require Order for the value on Cogen for SortedMap and NonEmptyMap --- laws/src/main/scala/cats/laws/discipline/arbitrary.scala | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/laws/src/main/scala/cats/laws/discipline/arbitrary.scala b/laws/src/main/scala/cats/laws/discipline/arbitrary.scala index 1c096a013b..b782e998ea 100644 --- a/laws/src/main/scala/cats/laws/discipline/arbitrary.scala +++ b/laws/src/main/scala/cats/laws/discipline/arbitrary.scala @@ -130,7 +130,7 @@ object arbitrary extends ArbitraryInstances0 with ScalaVersionSpecific.Arbitrary a <- A.arbitrary } yield NonEmptyMap((k, a), fa)) - implicit def cogenNonEmptyMap[K: Order: Cogen, A: Order: Cogen]: Cogen[NonEmptyMap[K, A]] = + implicit def cogenNonEmptyMap[K: Order: Cogen, A: Cogen]: Cogen[NonEmptyMap[K, A]] = Cogen[SortedMap[K, A]].contramap(_.toSortedMap) implicit def catsLawsArbitraryForEitherT[F[_], A, B](implicit @@ -286,9 +286,8 @@ object arbitrary extends ArbitraryInstances0 with ScalaVersionSpecific.Arbitrary implicit def catsLawsArbitraryForSortedMap[K: Arbitrary: Order, V: Arbitrary]: Arbitrary[SortedMap[K, V]] = Arbitrary(getArbitrary[Map[K, V]].map(s => SortedMap.empty[K, V](implicitly[Order[K]].toOrdering) ++ s)) - implicit def catsLawsCogenForSortedMap[K: Order: Cogen, V: Order: Cogen]: Cogen[SortedMap[K, V]] = { + implicit def catsLawsCogenForSortedMap[K: Order: Cogen, V: Cogen]: Cogen[SortedMap[K, V]] = { implicit val orderingK: Ordering[K] = Order[K].toOrdering - implicit val orderingV: Ordering[V] = Order[V].toOrdering implicitly[Cogen[Map[K, V]]].contramap(_.toMap) } From e4236f5bafe0aee39b36ebc22bd22d8071ac472b Mon Sep 17 00:00:00 2001 From: Carlos Quiroz <3615303+cquiroz@users.noreply.github.com> Date: Sun, 11 Sep 2022 13:07:57 -0300 Subject: [PATCH 2/3] Preserve previous signatures for binary compatibility --- .../cats/laws/discipline/arbitrary.scala | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/laws/src/main/scala/cats/laws/discipline/arbitrary.scala b/laws/src/main/scala/cats/laws/discipline/arbitrary.scala index b782e998ea..86816838c5 100644 --- a/laws/src/main/scala/cats/laws/discipline/arbitrary.scala +++ b/laws/src/main/scala/cats/laws/discipline/arbitrary.scala @@ -130,6 +130,19 @@ object arbitrary extends ArbitraryInstances0 with ScalaVersionSpecific.Arbitrary a <- A.arbitrary } yield NonEmptyMap((k, a), fa)) + @deprecated("Preserved for bincompat", "2.9.0") + def cogenNonEmptyMap[K, A](kOrder: Order[K], + kCogen: Cogen[K], + aOrder: Order[A], + aCogen: Cogen[A] + ): Cogen[NonEmptyMap[K, A]] = { + implicit val orderingK: Order[K] = kOrder + implicit val cogenK: Cogen[K] = kCogen + implicit val cogenA: Cogen[A] = aCogen + + Cogen[SortedMap[K, A]].contramap(_.toSortedMap) + } + implicit def cogenNonEmptyMap[K: Order: Cogen, A: Cogen]: Cogen[NonEmptyMap[K, A]] = Cogen[SortedMap[K, A]].contramap(_.toSortedMap) @@ -283,6 +296,19 @@ object arbitrary extends ArbitraryInstances0 with ScalaVersionSpecific.Arbitrary implicit def catsLawsArbitraryForOrder[A: Arbitrary]: Arbitrary[Order[A]] = Arbitrary(getArbitrary[Int => Int].map(f => Order.by(x => f(x.##)))) + @deprecated("Preserved for bincompat", "2.9.0") + def catsLawsCogenForSortedMap[K, V](kOrder: Order[K], + kCogen: Cogen[K], + vOrder: Order[V], + vCogen: Cogen[V] + ): Cogen[SortedMap[K, V]] = { + implicit val orderingK: Ordering[K] = kOrder.toOrdering + implicit val cogenK: Cogen[K] = kCogen + implicit val cogenA: Cogen[V] = vCogen + + implicitly[Cogen[Map[K, V]]].contramap(_.toMap) + } + implicit def catsLawsArbitraryForSortedMap[K: Arbitrary: Order, V: Arbitrary]: Arbitrary[SortedMap[K, V]] = Arbitrary(getArbitrary[Map[K, V]].map(s => SortedMap.empty[K, V](implicitly[Order[K]].toOrdering) ++ s)) From a704e1dd4917f5013c6fcdc62dc6e432b1cf639d Mon Sep 17 00:00:00 2001 From: Carlos Quiroz <3615303+cquiroz@users.noreply.github.com> Date: Sun, 11 Sep 2022 13:42:16 -0300 Subject: [PATCH 3/3] Delegate deprecated cogen methods to the new ones --- .../main/scala/cats/laws/discipline/arbitrary.scala | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/laws/src/main/scala/cats/laws/discipline/arbitrary.scala b/laws/src/main/scala/cats/laws/discipline/arbitrary.scala index 86816838c5..4016d9ad95 100644 --- a/laws/src/main/scala/cats/laws/discipline/arbitrary.scala +++ b/laws/src/main/scala/cats/laws/discipline/arbitrary.scala @@ -140,7 +140,7 @@ object arbitrary extends ArbitraryInstances0 with ScalaVersionSpecific.Arbitrary implicit val cogenK: Cogen[K] = kCogen implicit val cogenA: Cogen[A] = aCogen - Cogen[SortedMap[K, A]].contramap(_.toSortedMap) + cogenNonEmptyMap[K, A] } implicit def cogenNonEmptyMap[K: Order: Cogen, A: Cogen]: Cogen[NonEmptyMap[K, A]] = @@ -296,22 +296,22 @@ object arbitrary extends ArbitraryInstances0 with ScalaVersionSpecific.Arbitrary implicit def catsLawsArbitraryForOrder[A: Arbitrary]: Arbitrary[Order[A]] = Arbitrary(getArbitrary[Int => Int].map(f => Order.by(x => f(x.##)))) + implicit def catsLawsArbitraryForSortedMap[K: Arbitrary: Order, V: Arbitrary]: Arbitrary[SortedMap[K, V]] = + Arbitrary(getArbitrary[Map[K, V]].map(s => SortedMap.empty[K, V](implicitly[Order[K]].toOrdering) ++ s)) + @deprecated("Preserved for bincompat", "2.9.0") def catsLawsCogenForSortedMap[K, V](kOrder: Order[K], kCogen: Cogen[K], vOrder: Order[V], vCogen: Cogen[V] ): Cogen[SortedMap[K, V]] = { - implicit val orderingK: Ordering[K] = kOrder.toOrdering + implicit val orderingK: Order[K] = kOrder implicit val cogenK: Cogen[K] = kCogen implicit val cogenA: Cogen[V] = vCogen - implicitly[Cogen[Map[K, V]]].contramap(_.toMap) + catsLawsCogenForSortedMap[K, V] } - implicit def catsLawsArbitraryForSortedMap[K: Arbitrary: Order, V: Arbitrary]: Arbitrary[SortedMap[K, V]] = - Arbitrary(getArbitrary[Map[K, V]].map(s => SortedMap.empty[K, V](implicitly[Order[K]].toOrdering) ++ s)) - implicit def catsLawsCogenForSortedMap[K: Order: Cogen, V: Cogen]: Cogen[SortedMap[K, V]] = { implicit val orderingK: Ordering[K] = Order[K].toOrdering