Skip to content

Commit

Permalink
upgrade Hash in the same style as done in typelevel/cats#1997
Browse files Browse the repository at this point in the history
In this commit, the "on" method was removed from cat's Eq trait.
The "by" method which was using that method was reimplemented..
  • Loading branch information
rintcius committed Aug 24, 2018
1 parent a1e49ad commit a236544
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions src/main/scala/com/rklaehn/radixtree/Hash.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,6 @@ import scala.util.hashing.Hashing
*/
trait Hash[@sp A] extends Any with Eq[A] with Serializable { self =>
def hash(a: A): Int
/**
* Constructs a new `Eq` instance for type `B` where 2 elements are
* equivalent iff `eqv(f(x), f(y))`.
*/
def on[@sp B](f: B => A): Hash[B] =
new Hash[B] {
def eqv(x: B, y: B): Boolean = self.eqv(f(x), f(y))
def hash(x: B): Int = self.hash(f(x))
}
}

trait HashFunctions {
Expand Down Expand Up @@ -83,7 +74,10 @@ object Hash extends HashFunctions {
* using the given function `f`.
*/
def by[@sp A, @sp B](f: A => B)(implicit ev: Hash[B]): Hash[A] =
ev.on(f)
new Hash[A] {
def eqv(x: A, y: A): Boolean = ev.eqv(f(x), f(y))
def hash(x: A): Int = ev.hash(f(x))
}

/*
/**
Expand Down

0 comments on commit a236544

Please sign in to comment.