Skip to content

Commit

Permalink
Move contravariant instances to separate trait, in accordance with (t…
Browse files Browse the repository at this point in the history
  • Loading branch information
ctongfei authored and Luka Jacobowitz committed Sep 8, 2017
1 parent bf96364 commit f645496
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions core/src/main/scala/cats/instances/all.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ trait AllInstances
with EquivInstances
with FunctionInstances
with FutureInstances
with HashInstances
with ListInstances
with MapInstances
with MonoidInstances
Expand Down
18 changes: 18 additions & 0 deletions core/src/main/scala/cats/instances/hash.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package cats
package instances

import cats.functor._

/**
* @author Tongfei Chen
*/
trait HashInstances {
implicit val catsFunctorContravariantForHash: Contravariant[Hash] =
new Contravariant[Hash] {
/** Derive an `Hash` for `B` given an `Hash[A]` and a function `B => A`.
*
* Note: resulting instances are law-abiding only when the functions used are injective (represent a one-to-one mapping)
*/
def contramap[A, B](fa: Hash[A])(f: B => A): Hash[B] = Hash.by(f)(fa)
}
}

0 comments on commit f645496

Please sign in to comment.