Skip to content

Commit

Permalink
Add Order->Ordering implicit conversion to implicits, instances
Browse files Browse the repository at this point in the history
  • Loading branch information
edmundnoble committed Jun 28, 2017
1 parent bbc97b8 commit ed8c873
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion core/src/main/scala/cats/instances/order.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package instances

import cats.functor.Contravariant

trait OrderInstances {
trait OrderInstances extends cats.kernel.OrderToOrderingConversion {

implicit val catsFunctorContravariantForOrder: Contravariant[Order] =
new Contravariant[Order] {
Expand All @@ -14,3 +14,4 @@ trait OrderInstances {
def contramap[A, B](fa: Order[A])(f: B => A): Order[B] = fa.on(f)
}
}

9 changes: 9 additions & 0 deletions kernel/src/main/scala/cats/kernel/Order.scala
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,15 @@ abstract class OrderFunctions[O[T] <: Order[T]] extends PartialOrderFunctions[O]
ev.max(x, y)
}

trait OrderToOrderingConversion {
/**
* Implicitly derive a `scala.math.Ordering[A]` from a `Order[A]`
* instance.
*/
implicit def catsKernelOrderingForOrder[A](implicit ev: Order[A]): Ordering[A] =
ev.toOrdering
}

object Order extends OrderFunctions[Order] {
/**
* Access an implicit `Order[A]`.
Expand Down

0 comments on commit ed8c873

Please sign in to comment.