Ordering

scala.math.Ordering$
See theOrdering companion trait

This is the companion object for the scala.math.Ordering trait.

It contains many implicit orderings as well as well as methods to construct new orderings.

Attributes

Companion
trait
Source
Ordering.scala
Graph
Supertypes
Self type
Ordering.type

Members list

Type members

Classlikes

Attributes

Source
Ordering.scala
Supertypes
Self type
BigDecimal.type

Attributes

Source
Ordering.scala
Supertypes
trait Equiv[BigDecimal]
trait Serializable
class Object
trait Matchable
class Any
Show all
Known subtypes
object BigDecimal.type
object BigInt extends BigIntOrdering

Attributes

Source
Ordering.scala
Supertypes
trait Ordering[BigInt]
trait Equiv[BigInt]
trait Serializable
class Object
trait Matchable
class Any
Show all
Self type
BigInt.type
trait BigIntOrdering extends Ordering[BigInt]

Attributes

Source
Ordering.scala
Supertypes
trait Ordering[BigInt]
trait Equiv[BigInt]
trait Serializable
class Object
trait Matchable
class Any
Show all
Known subtypes
object BigIntIsIntegral.type
object BigInt.type
object Boolean extends BooleanOrdering

Attributes

Source
Ordering.scala
Supertypes
trait Ordering[Boolean]
trait Equiv[Boolean]
trait Serializable
class Object
trait Matchable
class Any
Show all
Self type
Boolean.type

Attributes

Source
Ordering.scala
Supertypes
trait Ordering[Boolean]
trait Equiv[Boolean]
trait Serializable
class Object
trait Matchable
class Any
Show all
Known subtypes
object Boolean.type
object Byte extends ByteOrdering

Attributes

Source
Ordering.scala
Supertypes
trait ByteOrdering
trait Ordering[Byte]
trait Equiv[Byte]
trait Serializable
trait Comparator[Byte]
class Object
trait Matchable
class Any
Show all
Self type
Byte.type
trait ByteOrdering extends Ordering[Byte]

Attributes

Source
Ordering.scala
Supertypes
trait Ordering[Byte]
trait Equiv[Byte]
trait Serializable
trait Comparator[Byte]
class Object
trait Matchable
class Any
Show all
Known subtypes
object ByteIsIntegral.type
object Byte.type
sealed trait CachedReverse[T] extends Ordering[T]

An ordering which caches the value of its reverse.

An ordering which caches the value of its reverse.

Attributes

Source
Ordering.scala
Supertypes
trait Ordering[T]
trait PartialOrdering[T]
trait Equiv[T]
trait Serializable
trait Comparator[T]
class Object
trait Matchable
class Any
Show all
Known subtypes
object Int.type
object Char extends CharOrdering

Attributes

Source
Ordering.scala
Supertypes
trait CharOrdering
trait Ordering[Char]
trait Equiv[Char]
trait Serializable
trait Comparator[Char]
class Object
trait Matchable
class Any
Show all
Self type
Char.type
trait CharOrdering extends Ordering[Char]

Attributes

Source
Ordering.scala
Supertypes
trait Ordering[Char]
trait Equiv[Char]
trait Serializable
trait Comparator[Char]
class Object
trait Matchable
class Any
Show all
Known subtypes
object CharIsIntegral.type
object Char.type

Attributes

Source
Ordering.scala
Supertypes
trait Ordering[Double]
trait Equiv[Double]
trait Serializable
class Object
trait Matchable
class Any
Show all
Self type

Attributes

Source
Ordering.scala
Supertypes
trait Ordering[Float]
trait Equiv[Float]
trait Serializable
trait Comparator[Float]
class Object
trait Matchable
class Any
Show all
Self type
object Double

Orderings for Doubles.

Orderings for Doubles.

The behavior of the comparison operations provided by the default (implicit) ordering on Double changed in 2.10.0 and 2.13.0. Prior to Scala 2.10.0, the Ordering instance used semantics consistent with java.lang.Double.compare.

Scala 2.10.0 changed the implementation of lt, equiv, min, etc., to be IEEE 754 compliant, while keeping the compare method NOT compliant, creating an internally inconsistent instance. IEEE 754 specifies that 0.0 == -0.0. In addition, it requires all comparisons with Double.NaN return false thus 0.0 < Double.NaN, 0.0 > Double.NaN, and Double.NaN == Double.NaN all yield false, analogous None in flatMap.

Recognizing the limitation of the IEEE 754 semantics in terms of ordering, Scala 2.13.0 created two instances: Ordering.Double.IeeeOrdering, which retains the IEEE 754 semantics from Scala 2.12.x, and Ordering.Double.TotalOrdering, which brings back the java.lang.Double.compare semantics for all operations. The default extends TotalOrdering.

List(0.0, 1.0, 0.0 / 0.0, -1.0 / 0.0).sorted      // List(-Infinity, 0.0, 1.0, NaN)
List(0.0, 1.0, 0.0 / 0.0, -1.0 / 0.0).min         // -Infinity
implicitly[Ordering[Double]].lt(0.0, 0.0 / 0.0)   // true
{
  import Ordering.Double.IeeeOrdering
  List(0.0, 1.0, 0.0 / 0.0, -1.0 / 0.0).sorted    // List(-Infinity, 0.0, 1.0, NaN)
  List(0.0, 1.0, 0.0 / 0.0, -1.0 / 0.0).min       // NaN
  implicitly[Ordering[Double]].lt(0.0, 0.0 / 0.0) // false
}

Attributes

Source
Ordering.scala
Supertypes
class Object
trait Matchable
class Any
Self type
Double.type

Attributes

Source
Ordering.scala
Supertypes
class Object
trait Matchable
class Any
Known subtypes
object Implicits.type
object Float

Orderings for Floats.

Orderings for Floats.

The behavior of the comparison operations provided by the default (implicit) ordering on Float changed in 2.10.0 and 2.13.0. Prior to Scala 2.10.0, the Ordering instance used semantics consistent with java.lang.Float.compare.

Scala 2.10.0 changed the implementation of lt, equiv, min, etc., to be IEEE 754 compliant, while keeping the compare method NOT compliant, creating an internally inconsistent instance. IEEE 754 specifies that 0.0F == -0.0F. In addition, it requires all comparisons with Float.NaN return false thus 0.0F < Float.NaN, 0.0F > Float.NaN, and Float.NaN == Float.NaN all yield false, analogous None in flatMap.

Recognizing the limitation of the IEEE 754 semantics in terms of ordering, Scala 2.13.0 created two instances: Ordering.Float.IeeeOrdering, which retains the IEEE 754 semantics from Scala 2.12.x, and Ordering.Float.TotalOrdering, which brings back the java.lang.Float.compare semantics for all operations. The default extends TotalOrdering.

List(0.0F, 1.0F, 0.0F / 0.0F, -1.0F / 0.0F).sorted      // List(-Infinity, 0.0, 1.0, NaN)
List(0.0F, 1.0F, 0.0F / 0.0F, -1.0F / 0.0F).min         // -Infinity
implicitly[Ordering[Float]].lt(0.0F, 0.0F / 0.0F)       // true
{
  import Ordering.Float.IeeeOrdering
  List(0.0F, 1.0F, 0.0F / 0.0F, -1.0F / 0.0F).sorted    // List(-Infinity, 0.0, 1.0, NaN)
  List(0.0F, 1.0F, 0.0F / 0.0F, -1.0F / 0.0F).min       // NaN
  implicitly[Ordering[Float]].lt(0.0F, 0.0F / 0.0F)     // false
}

Attributes

Source
Ordering.scala
Supertypes
class Object
trait Matchable
class Any
Self type
Float.type
object Implicits extends ExtraImplicits

An object containing implicits which are not in the default scope.

An object containing implicits which are not in the default scope.

Attributes

Source
Ordering.scala
Supertypes
class Object
trait Matchable
class Any
Self type
Implicits.type
object Int extends IntOrdering, CachedReverse[Int]

Attributes

Source
Ordering.scala
Supertypes
trait IntOrdering
trait Ordering[Int]
trait Equiv[Int]
trait Serializable
trait Comparator[Int]
class Object
trait Matchable
class Any
Show all
Self type
Int.type
trait IntOrdering extends Ordering[Int]

Attributes

Source
Ordering.scala
Supertypes
trait Ordering[Int]
trait Equiv[Int]
trait Serializable
trait Comparator[Int]
class Object
trait Matchable
class Any
Show all
Known subtypes
object IntIsIntegral.type
object Int.type
object Long extends LongOrdering

Attributes

Source
Ordering.scala
Supertypes
trait LongOrdering
trait Ordering[Long]
trait Equiv[Long]
trait Serializable
trait Comparator[Long]
class Object
trait Matchable
class Any
Show all
Self type
Long.type
trait LongOrdering extends Ordering[Long]

Attributes

Source
Ordering.scala
Supertypes
trait Ordering[Long]
trait Equiv[Long]
trait Serializable
trait Comparator[Long]
class Object
trait Matchable
class Any
Show all
Known subtypes
object LongIsIntegral.type
object Long.type
trait OptionOrdering[T] extends Ordering[Option[T]]

Attributes

Source
Ordering.scala
Supertypes
trait Ordering[Option[T]]
trait Equiv[Option[T]]
trait Serializable
trait Comparator[Option[T]]
class Object
trait Matchable
class Any
Show all
object Short extends ShortOrdering

Attributes

Source
Ordering.scala
Supertypes
trait Ordering[Short]
trait Equiv[Short]
trait Serializable
trait Comparator[Short]
class Object
trait Matchable
class Any
Show all
Self type
Short.type
trait ShortOrdering extends Ordering[Short]

Attributes

Source
Ordering.scala
Supertypes
trait Ordering[Short]
trait Equiv[Short]
trait Serializable
trait Comparator[Short]
class Object
trait Matchable
class Any
Show all
Known subtypes
object ShortIsIntegral.type
object Short.type
object String extends StringOrdering

Attributes

Source
Ordering.scala
Supertypes
trait Ordering[String]
trait Equiv[String]
trait Serializable
class Object
trait Matchable
class Any
Show all
Self type
String.type
trait StringOrdering extends Ordering[String]

Attributes

Source
Ordering.scala
Supertypes
trait Ordering[String]
trait Equiv[String]
trait Serializable
class Object
trait Matchable
class Any
Show all
Known subtypes
object String.type
object Symbol extends SymbolOrdering

Attributes

Source
Ordering.scala
Supertypes
trait Ordering[Symbol]
trait Equiv[Symbol]
trait Serializable
class Object
trait Matchable
class Any
Show all
Self type
Symbol.type
trait SymbolOrdering extends Ordering[Symbol]

Attributes

Source
Ordering.scala
Supertypes
trait Ordering[Symbol]
trait Equiv[Symbol]
trait Serializable
class Object
trait Matchable
class Any
Show all
Known subtypes
object Symbol.type
object Unit extends UnitOrdering

Attributes

Source
Ordering.scala
Supertypes
trait UnitOrdering
trait Ordering[Unit]
trait Equiv[Unit]
trait Serializable
trait Comparator[Unit]
class Object
trait Matchable
class Any
Show all
Self type
Unit.type
trait UnitOrdering extends Ordering[Unit]

Attributes

Source
Ordering.scala
Supertypes
trait Ordering[Unit]
trait Equiv[Unit]
trait Serializable
trait Comparator[Unit]
class Object
trait Matchable
class Any
Show all
Known subtypes
object Unit.type

Inherited types

type AsComparable[A] = A => Comparable[_ >: A]

Attributes

Inherited from:
LowPriorityOrderingImplicits
Source
Ordering.scala

Value members

Concrete methods

def apply[T](implicit ord: Ordering[T]): Ordering[T]

Attributes

Source
Ordering.scala
def by[T, S](f: T => S)(implicit ord: Ordering[S]): Ordering[T]

Given f, a function from T into S, creates an Ordering[T] whose compare function is equivalent to:

Given f, a function from T into S, creates an Ordering[T] whose compare function is equivalent to:

def compare(x:T, y:T) = Ordering[S].compare(f(x), f(y))

This function is an analogue to Ordering.on where the Ordering[S] parameter is passed implicitly.

Attributes

Source
Ordering.scala
def fromLessThan[T](cmp: (T, T) => Boolean): Ordering[T]

Construct an Ordering[T] given a function lt.

Construct an Ordering[T] given a function lt.

Attributes

Source
Ordering.scala

Implicits

Implicits

implicit def Option[T](implicit ord: Ordering[T]): Ordering[Option[T]]

Attributes

Source
Ordering.scala
implicit def Tuple2[T1, T2](implicit ord1: Ordering[T1], ord2: Ordering[T2]): Ordering[(T1, T2)]

Attributes

Source
Ordering.scala
implicit def Tuple3[T1, T2, T3](implicit ord1: Ordering[T1], ord2: Ordering[T2], ord3: Ordering[T3]): Ordering[(T1, T2, T3)]

Attributes

Source
Ordering.scala
implicit def Tuple4[T1, T2, T3, T4](implicit ord1: Ordering[T1], ord2: Ordering[T2], ord3: Ordering[T3], ord4: Ordering[T4]): Ordering[(T1, T2, T3, T4)]

Attributes

Source
Ordering.scala
implicit def Tuple5[T1, T2, T3, T4, T5](implicit ord1: Ordering[T1], ord2: Ordering[T2], ord3: Ordering[T3], ord4: Ordering[T4], ord5: Ordering[T5]): Ordering[(T1, T2, T3, T4, T5)]

Attributes

Source
Ordering.scala
implicit def Tuple6[T1, T2, T3, T4, T5, T6](implicit ord1: Ordering[T1], ord2: Ordering[T2], ord3: Ordering[T3], ord4: Ordering[T4], ord5: Ordering[T5], ord6: Ordering[T6]): Ordering[(T1, T2, T3, T4, T5, T6)]

Attributes

Source
Ordering.scala
implicit def Tuple7[T1, T2, T3, T4, T5, T6, T7](implicit ord1: Ordering[T1], ord2: Ordering[T2], ord3: Ordering[T3], ord4: Ordering[T4], ord5: Ordering[T5], ord6: Ordering[T6], ord7: Ordering[T7]): Ordering[(T1, T2, T3, T4, T5, T6, T7)]

Attributes

Source
Ordering.scala
implicit def Tuple8[T1, T2, T3, T4, T5, T6, T7, T8](implicit ord1: Ordering[T1], ord2: Ordering[T2], ord3: Ordering[T3], ord4: Ordering[T4], ord5: Ordering[T5], ord6: Ordering[T6], ord7: Ordering[T7], ord8: Ordering[T8]): Ordering[(T1, T2, T3, T4, T5, T6, T7, T8)]

Attributes

Source
Ordering.scala
implicit def Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9](implicit ord1: Ordering[T1], ord2: Ordering[T2], ord3: Ordering[T3], ord4: Ordering[T4], ord5: Ordering[T5], ord6: Ordering[T6], ord7: Ordering[T7], ord8: Ordering[T8], ord9: Ordering[T9]): Ordering[(T1, T2, T3, T4, T5, T6, T7, T8, T9)]

Attributes

Source
Ordering.scala

Deprecated implicits

implicit def Iterable[T](implicit ord: Ordering[T]): Ordering[Iterable[T]]

Attributes

Deprecated
[Since version 2.13.0]

Iterables are not guaranteed to have a consistent order, so the Ordering returned by this method may not be stable or meaningful. If you are using a type with a consistent order (such as Seq), use its Ordering (found in the Implicits object) instead.

Source
Ordering.scala

Inherited implicits

implicit def comparatorToOrdering[A](implicit cmp: Comparator[A]): Ordering[A]

Attributes

Inherited from:
LowPriorityOrderingImplicits
Source
Ordering.scala
implicit def ordered[A](implicit asComparable: () => A): Ordering[A]

This would conflict with all the nice implicit Orderings available, but thanks to the magic of prioritized implicits via subclassing we can make Ordered[A] => Ordering[A] only turn up if nothing else works.

This would conflict with all the nice implicit Orderings available, but thanks to the magic of prioritized implicits via subclassing we can make Ordered[A] => Ordering[A] only turn up if nothing else works. Since Ordered[A] extends Comparable[A] anyway, we can throw in some Java interop too.

Attributes

Inherited from:
LowPriorityOrderingImplicits
Source
Ordering.scala