From 0f34e7cf8934b4538220f4c774635e27b92dec62 Mon Sep 17 00:00:00 2001 From: Kailuo Wang Date: Mon, 18 Dec 2017 11:13:40 -0500 Subject: [PATCH] added hash conversion --- core/src/main/scala/cats/instances/hash.scala | 2 +- kernel/src/main/scala/cats/kernel/Hash.scala | 6 ++++++ kernel/src/main/scala/cats/kernel/instances/all.scala | 1 + kernel/src/main/scala/cats/kernel/instances/hash.scala | 6 ++++++ 4 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 kernel/src/main/scala/cats/kernel/instances/hash.scala diff --git a/core/src/main/scala/cats/instances/hash.scala b/core/src/main/scala/cats/instances/hash.scala index 443ef96e394..2401313148a 100644 --- a/core/src/main/scala/cats/instances/hash.scala +++ b/core/src/main/scala/cats/instances/hash.scala @@ -2,7 +2,7 @@ package cats package instances -trait HashInstances { +trait HashInstances extends kernel.instances.HashInstances { implicit val catsContravariantForHash: Contravariant[Hash] = new Contravariant[Hash] { diff --git a/kernel/src/main/scala/cats/kernel/Hash.scala b/kernel/src/main/scala/cats/kernel/Hash.scala index ef8e88d742a..4579f121848 100644 --- a/kernel/src/main/scala/cats/kernel/Hash.scala +++ b/kernel/src/main/scala/cats/kernel/Hash.scala @@ -54,3 +54,9 @@ object Hash extends HashFunctions[Hash] { } } + +trait HashToHashingConversion { + implicit def catsKernelHashToHashing[A](implicit ev: Hash[A]): Hashing[A] = new Hashing[A] { + override def hash(x: A): Int = ev.hash(x) + } +} diff --git a/kernel/src/main/scala/cats/kernel/instances/all.scala b/kernel/src/main/scala/cats/kernel/instances/all.scala index 1b5866c7c18..1af2f0b0dad 100644 --- a/kernel/src/main/scala/cats/kernel/instances/all.scala +++ b/kernel/src/main/scala/cats/kernel/instances/all.scala @@ -16,6 +16,7 @@ trait AllInstances with DurationInstances with FloatInstances with FunctionInstances + with HashInstances with IntInstances with ListInstances with LongInstances diff --git a/kernel/src/main/scala/cats/kernel/instances/hash.scala b/kernel/src/main/scala/cats/kernel/instances/hash.scala new file mode 100644 index 00000000000..38220965962 --- /dev/null +++ b/kernel/src/main/scala/cats/kernel/instances/hash.scala @@ -0,0 +1,6 @@ +package cats.kernel +package instances + +trait HashInstances extends HashToHashingConversion + +object hash extends HashInstances