diff --git a/core/src/main/scala/cats/data/NonEmptyMapImpl.scala b/core/src/main/scala/cats/data/NonEmptyMapImpl.scala index aae059c1c0..3195c88694 100644 --- a/core/src/main/scala/cats/data/NonEmptyMapImpl.scala +++ b/core/src/main/scala/cats/data/NonEmptyMapImpl.scala @@ -265,7 +265,7 @@ sealed class NonEmptyMapOps[K, A](val value: NonEmptyMap[K, A]) { def toNel: NonEmptyList[(K, A)] = NonEmptyList.fromListUnsafe(toSortedMap.toList) } -sealed abstract private[data] class NonEmptyMapInstances { +sealed abstract private[data] class NonEmptyMapInstances extends NonEmptyMapInstances0 { implicit def catsDataInstancesForNonEmptyMap[K: Order] : SemigroupK[NonEmptyMap[K, *]] with NonEmptyTraverse[NonEmptyMap[K, *]] = @@ -318,10 +318,8 @@ sealed abstract private[data] class NonEmptyMapInstances { NonEmptyList(fa.head._2, fa.tail.toList.map(_._2)) } - implicit def catsDataEqForNonEmptyMap[K: Order, A: Eq]: Eq[NonEmptyMap[K, A]] = - new Eq[NonEmptyMap[K, A]] { - def eqv(x: NonEmptyMap[K, A], y: NonEmptyMap[K, A]): Boolean = x === y - } + implicit def catsDataHashForNonEmptyMap[K: Hash: Order, A: Hash]: Hash[NonEmptyMap[K, A]] = + Hash[SortedMap[K, A]].asInstanceOf[Hash[NonEmptyMap[K, A]]] implicit def catsDataShowForNonEmptyMap[K: Show, A: Show]: Show[NonEmptyMap[K, A]] = Show.show[NonEmptyMap[K, A]](_.show) @@ -330,3 +328,10 @@ sealed abstract private[data] class NonEmptyMapInstances { def combine(x: NonEmptyMap[K, A], y: NonEmptyMap[K, A]): NonEmptyMap[K, A] = x ++ y } } + +sealed abstract private[data] class NonEmptyMapInstances0 { + implicit def catsDataEqForNonEmptyMap[K: Order, A: Eq]: Eq[NonEmptyMap[K, A]] = + new Eq[NonEmptyMap[K, A]] { + def eqv(x: NonEmptyMap[K, A], y: NonEmptyMap[K, A]): Boolean = x === y + } +} diff --git a/tests/src/test/scala/cats/tests/NonEmptyMapSuite.scala b/tests/src/test/scala/cats/tests/NonEmptyMapSuite.scala index 244706e46e..2b61a76f02 100644 --- a/tests/src/test/scala/cats/tests/NonEmptyMapSuite.scala +++ b/tests/src/test/scala/cats/tests/NonEmptyMapSuite.scala @@ -33,6 +33,7 @@ class NonEmptyMapSuite extends CatsSuite { ) checkAll("NonEmptyMap[String, Int]", BandTests[NonEmptyMap[String, Int]].band) checkAll("NonEmptyMap[String, Int]", EqTests[NonEmptyMap[String, Int]].eqv) + checkAll("NonEmptyMap[String, Int]", HashTests[NonEmptyMap[String, Int]].hash) test("Show is not empty and is formatted as expected") { forAll { (nem: NonEmptyMap[String, Int]) =>