object Ordering extends LowPriorityOrderingImplicits with java.io.Serializable
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.
- Source
- Ordering.scala
- Alphabetic
- By Inheritance
- Ordering
- Serializable
- LowPriorityOrderingImplicits
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Type Members
- type AsComparable[A] = (A) => Comparable[_ >: A]
- Definition Classes
- LowPriorityOrderingImplicits
- trait BigDecimalOrdering extends Ordering[BigDecimal]
- trait BigIntOrdering extends Ordering[BigInt]
- trait BooleanOrdering extends Ordering[Boolean]
- trait ByteOrdering extends Ordering[Byte]
- sealed trait CachedReverse[T] extends Ordering[T]
An ordering which caches the value of its reverse.
- trait CharOrdering extends Ordering[Char]
- trait ExtraImplicits extends AnyRef
- trait IntOrdering extends Ordering[Int]
- trait LongOrdering extends Ordering[Long]
- trait OptionOrdering[T] extends Ordering[Option[T]]
- trait ShortOrdering extends Ordering[Short]
- trait StringOrdering extends Ordering[String]
- trait SymbolOrdering extends Ordering[Symbol]
- trait UnitOrdering extends Ordering[Unit]
Value Members
- implicit def Option[T](implicit ord: Ordering[T]): Ordering[Option[T]]
- implicit def Tuple2[T1, T2](implicit ord1: Ordering[T1], ord2: Ordering[T2]): Ordering[(T1, T2)]
- implicit def Tuple3[T1, T2, T3](implicit ord1: Ordering[T1], ord2: Ordering[T2], ord3: Ordering[T3]): Ordering[(T1, T2, T3)]
- 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)]
- 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)]
- 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)]
- Annotations
- @SerialVersionUID()
- 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)]
- 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)]
- Annotations
- @SerialVersionUID()
- 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)]
- Annotations
- @SerialVersionUID()
- def apply[T](implicit ord: Ordering[T]): Ordering[T]
- Annotations
- @inline()
- 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.
- implicit def comparatorToOrdering[A](implicit cmp: Comparator[A]): Ordering[A]
- Definition Classes
- LowPriorityOrderingImplicits
- def fromLessThan[T](cmp: (T, T) => Boolean): Ordering[T]
Construct an Ordering[T] given a function
lt
. - implicit def ordered[A](implicit asComparable: 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. SinceOrdered[A]
extendsComparable[A]
anyway, we can throw in some Java interop too.- Definition Classes
- LowPriorityOrderingImplicits
- implicit object BigDecimal extends BigDecimalOrdering
- Annotations
- @SerialVersionUID()
- implicit object BigInt extends BigIntOrdering
- Annotations
- @SerialVersionUID()
- implicit object Boolean extends BooleanOrdering
- Annotations
- @SerialVersionUID()
- implicit object Byte extends ByteOrdering
- Annotations
- @SerialVersionUID()
- implicit object Char extends CharOrdering
- Annotations
- @SerialVersionUID()
- implicit object DeprecatedDoubleOrdering extends TotalOrdering
- Annotations
- @migration @SerialVersionUID()
- Migration
(Changed in version 2.13.0) The default implicit ordering for doubles now maintains consistency between its
compare
method and itslt
,min
,equiv
, etc., methods, which means nonconforming to IEEE 754's behavior for -0.0 and NaN. The sort order of doubles remains the same, however, with NaN at the end. Import Ordering.Double.IeeeOrdering to recover the previous behavior. See also https://www.scala-lang.org/api/current/scala/math/Ordering$$Double$.html.
- implicit object DeprecatedFloatOrdering extends TotalOrdering
- Annotations
- @migration @SerialVersionUID()
- Migration
(Changed in version 2.13.0) The default implicit ordering for floats now maintains consistency between its
compare
method and itslt
,min
,equiv
, etc., methods, which means nonconforming to IEEE 754's behavior for -0.0F and NaN. The sort order of floats remains the same, however, with NaN at the end. Import Ordering.Float.IeeeOrdering to recover the previous behavior. See also https://www.scala-lang.org/api/current/scala/math/Ordering$$Float$.html.
- object Double
Ordering
s forDouble
s.Ordering
s forDouble
s.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, theOrdering
instance used semantics consistent withjava.lang.Double.compare
.Scala 2.10.0 changed the implementation of
lt
,equiv
,min
, etc., to be IEEE 754 compliant, while keeping thecompare
method NOT compliant, creating an internally inconsistent instance. IEEE 754 specifies that0.0 == -0.0
. In addition, it requires all comparisons withDouble.NaN
returnfalse
thus0.0 < Double.NaN
,0.0 > Double.NaN
, andDouble.NaN == Double.NaN
all yieldfalse
, analogousNone
inflatMap
.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, andOrdering.Double.TotalOrdering
, which brings back thejava.lang.Double.compare
semantics for all operations. The default extendsTotalOrdering
.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 }
- object Float
Ordering
s forFloat
s.Ordering
s forFloat
s.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, theOrdering
instance used semantics consistent withjava.lang.Float.compare
.Scala 2.10.0 changed the implementation of
lt
,equiv
,min
, etc., to be IEEE 754 compliant, while keeping thecompare
method NOT compliant, creating an internally inconsistent instance. IEEE 754 specifies that0.0F == -0.0F
. In addition, it requires all comparisons withFloat.NaN
returnfalse
thus0.0F < Float.NaN
,0.0F > Float.NaN
, andFloat.NaN == Float.NaN
all yieldfalse
, analogousNone
inflatMap
.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, andOrdering.Float.TotalOrdering
, which brings back thejava.lang.Float.compare
semantics for all operations. The default extendsTotalOrdering
.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 }
- object Implicits extends ExtraImplicits
An object containing implicits which are not in the default scope.
- implicit object Int extends IntOrdering with CachedReverse[Int]
- Annotations
- @SerialVersionUID()
- implicit object Long extends LongOrdering
- Annotations
- @SerialVersionUID()
- implicit object Short extends ShortOrdering
- Annotations
- @SerialVersionUID()
- implicit object String extends StringOrdering
- Annotations
- @SerialVersionUID()
- implicit object Symbol extends SymbolOrdering
- Annotations
- @SerialVersionUID()
- implicit object Unit extends UnitOrdering
- Annotations
- @SerialVersionUID()
Deprecated Value Members
- implicit def Iterable[T](implicit ord: Ordering[T]): Ordering[Iterable[T]]
- Annotations
- @deprecated
- Deprecated
(Since version 2.13.0) Iterables are not guaranteed to have a consistent order; if using a type with a consistent order (e.g. Seq), use its Ordering (found in the Ordering.Implicits object)
This is the documentation for the Scala standard library.
Package structure
The scala package contains core types like
Int
,Float
,Array
orOption
which are accessible in all Scala compilation units without explicit qualification or imports.Notable packages include:
scala.collection
and its sub-packages contain Scala's collections frameworkscala.collection.immutable
- Immutable, sequential data-structures such asVector
,List
,Range
,HashMap
orHashSet
scala.collection.mutable
- Mutable, sequential data-structures such asArrayBuffer
,StringBuilder
,HashMap
orHashSet
scala.collection.concurrent
- Mutable, concurrent data-structures such asTrieMap
scala.concurrent
- Primitives for concurrent programming such asFutures
andPromises
scala.io
- Input and output operationsscala.math
- Basic math functions and additional numeric types likeBigInt
andBigDecimal
scala.sys
- Interaction with other processes and the operating systemscala.util.matching
- Regular expressionsOther packages exist. See the complete list on the right.
Additional parts of the standard library are shipped as separate libraries. These include:
scala.reflect
- Scala's reflection API (scala-reflect.jar)scala.xml
- XML parsing, manipulation, and serialization (scala-xml.jar)scala.collection.parallel
- Parallel collections (scala-parallel-collections.jar)scala.util.parsing
- Parser combinators (scala-parser-combinators.jar)scala.swing
- A convenient wrapper around Java's GUI framework called Swing (scala-swing.jar)Automatic imports
Identifiers in the scala package and the
scala.Predef
object are always in scope by default.Some of these identifiers are type aliases provided as shortcuts to commonly used classes. For example,
List
is an alias forscala.collection.immutable.List
.Other aliases refer to classes provided by the underlying platform. For example, on the JVM,
String
is an alias forjava.lang.String
.