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 May 14, 2017
1 parent 9f98924 commit b7aa10c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 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 @@ -20,3 +20,4 @@ trait AllInstances
with TupleInstances
with UUIDInstances
with SymbolInstances
with OrderInstances
5 changes: 5 additions & 0 deletions core/src/main/scala/cats/instances/order.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package cats
package instances

trait OrderInstances extends cats.kernel.OrderToOrderingConversion

1 change: 1 addition & 0 deletions core/src/main/scala/cats/instances/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ package object instances {
object try_ extends TryInstances
object tuple extends TupleInstances
object uuid extends UUIDInstances
object order extends OrderInstances
}
18 changes: 10 additions & 8 deletions kernel/src/main/scala/cats/kernel/Order.scala
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,16 @@ abstract class OrderFunctions[O[T] <: Order[T]] extends PartialOrderFunctions[O]
ev.max(x, y)
}

object Order extends OrderFunctions[Order] {
trait OrderToOrderingConversion {
/**
* Implicitly convert a `Order[A]` to a `scala.math.Ordering[A]`
* instance.
*/
implicit final def catsKernelOrderingForOrder[A](implicit ev: Order[A]): Ordering[A] =
ev.toOrdering
}

object Order extends OrderFunctions[Order] with OrderToOrderingConversion {
/**
* Access an implicit `Order[A]`.
*/
Expand All @@ -160,13 +169,6 @@ object Order extends OrderFunctions[Order] {
def compare(x: A, y: A) = f(x, y)
}

/**
* Implicitly convert a `Order[A]` to a `scala.math.Ordering[A]`
* instance.
*/
implicit def catsKernelOrderingForOrder[A](implicit ev: Order[A]): Ordering[A] =
ev.toOrdering

/**
* An `Order` instance that considers all `A` instances to be equal.
*/
Expand Down

0 comments on commit b7aa10c

Please sign in to comment.