Skip to content

Commit

Permalink
Add Hash instance for NonEmptySet. (#2981)
Browse files Browse the repository at this point in the history
* Add Hash instance for NonEmptySet.

* Hash inherits Eq.
  • Loading branch information
tanaka takaya authored and kailuowang committed Aug 9, 2019
1 parent 803f61c commit e50c00b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
3 changes: 0 additions & 3 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import java.time.LocalDateTime

import microsites._
import ReleaseTransformations._
import sbt.io.Using

import scala.xml.transform.{RewriteRule, RuleTransformer}
import sbtcrossproject.CrossProject
import sbtcrossproject.CrossPlugin.autoImport.{crossProject, CrossType}

lazy val scoverageSettings = Seq(
Expand Down
7 changes: 6 additions & 1 deletion core/src/main/scala/cats/data/NonEmptySet.scala
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,12 @@ sealed abstract private[data] class NonEmptySetInstances extends NonEmptySetInst
}
}

sealed abstract private[data] class NonEmptySetInstances0 {
sealed abstract private[data] class NonEmptySetInstances0 extends NonEmptySetInstances1 {
implicit def catsDataHashForNonEmptySet[A: Order: Hash]: Hash[NonEmptySet[A]] =
Hash[SortedSet[A]].asInstanceOf[Hash[NonEmptySet[A]]]
}

sealed abstract private[data] class NonEmptySetInstances1 {
implicit def catsDataEqForNonEmptySet[A](implicit A: Order[A]): Eq[NonEmptySet[A]] = new NonEmptySetEq[A] {
implicit override def A0: Eq[A] = A
}
Expand Down
3 changes: 2 additions & 1 deletion tests/src/test/scala/cats/tests/NonEmptySetSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import cats.laws.discipline._
import cats.laws.discipline.arbitrary._
import cats.data.NonEmptySet
import cats.kernel.Semilattice
import cats.kernel.laws.discipline.{EqTests, OrderTests, SemilatticeTests}
import cats.kernel.laws.discipline.{EqTests, HashTests, OrderTests, SemilatticeTests}

import scala.collection.immutable.SortedSet

Expand All @@ -37,6 +37,7 @@ class NonEmptySetSuite extends CatsSuite {
checkAll("Semilattice[NonEmptySet]", SerializableTests.serializable(Semilattice[NonEmptySet[String]]))

checkAll("NonEmptySet[String]", EqTests[NonEmptySet[String]].eqv)
checkAll("NonEmptySet[String]", HashTests[NonEmptySet[String]].hash)

{
implicit val A = ListWrapper.order[Int]
Expand Down

0 comments on commit e50c00b

Please sign in to comment.