Returns an integer whose sign communicates how x compares to y.
Returns an integer whose sign communicates how x compares to y.
The result sign has the following meaning:
Return true if x
== y
in the ordering.
Return true if x
== y
in the ordering.
Return true if x
> y
in the ordering.
Return true if x
> y
in the ordering.
Return true if x
>= y
in the ordering.
Return true if x
>= y
in the ordering.
Return true if x
< y
in the ordering.
Return true if x
< y
in the ordering.
Return true if x
<= y
in the ordering.
Return true if x
<= y
in the ordering.
Return x
if x
>= y
, otherwise y
.
Return x
if x
<= y
, otherwise y
.
This implicit method augments T
with the comparison operators defined
in scala.math.Ordering.Ops
.
Given f, a function from U into T, creates an Ordering[U] whose compare function is equivalent to:
Given f, a function from U into T, creates an Ordering[U] whose compare function is equivalent to:
def compare(x:U, y:U) = Ordering[T].compare(f(x), f(y))
Return the opposite ordering of this one.
Return the opposite ordering of this one.
Returns whether a comparison between x
and y
is defined, and if so
the result of compare(x, y)
.
Returns whether a comparison between x
and y
is defined, and if so
the result of compare(x, y)
.
Ordering is a trait whose instances each represent a strategy for sorting instances of a type.
Ordering's companion object defines many implicit objects to deal with subtypes of AnyVal (e.g. Int, Double), String, and others.
To sort instances by one or more member variables, you can take advantage of these built-in orderings using Ordering.by and Ordering.on:
An Ordering[T] is implemented by specifying compare(a:T, b:T), which decides how to order two instances a and b. Instances of Ordering[T] can be used by things like scala.util.Sorting to sort collections like Array[T].
For example:
This trait and scala.math.Ordered both provide this same functionality, but in different ways. A type T can be given a single way to order itself by extending Ordered. Using Ordering, this same type may be sorted in many other ways. Ordered and Ordering both provide implicits allowing them to be used interchangeably.
You can import scala.math.Ordering.Implicits to gain access to other implicit orderings.
0.9.5, 2008-04-15
2.7
scala.math.Ordered, scala.util.Sorting