Movatterモバイル変換


[0]ホーム

URL:


Scala 3
3.7.4
LearnInstallPlaygroundFind A LibraryCommunityBlog
Scala 3
LearnInstallPlaygroundFind A LibraryCommunityBlog
DocsAPI
Generated with
Copyright (c) 2002-2025, LAMP/EPFL
Copyright (c) 2002-2025, LAMP/EPFL
Scala 3/scala/scala.math/Ordering

Ordering

scala.math.Ordering
See theOrdering companion trait

This is the companion object for thescala.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

Members list

Type members

Classlikes

Attributes

Source
Ordering.scala
Supertypes
Self type

Attributes

Source
Ordering.scala
Supertypes
Known subtypes
objectBigInt extendsBigIntOrdering

Attributes

Source
Ordering.scala
Supertypes
Self type
BigInt.type

Attributes

Source
Ordering.scala
Supertypes
traitEquiv[BigInt]
classObject
traitMatchable
classAny
Show all
Known subtypes

Attributes

Source
Ordering.scala
Supertypes
Self type
Boolean.type

Attributes

Source
Ordering.scala
Supertypes
traitEquiv[Boolean]
classObject
traitMatchable
classAny
Show all
Known subtypes
objectBoolean
objectByte extendsByteOrdering

Attributes

Source
Ordering.scala
Supertypes
traitOrdering[Byte]
traitEquiv[Byte]
classObject
traitMatchable
classAny
Show all
Self type
Byte.type

Attributes

Source
Ordering.scala
Supertypes
traitOrdering[Byte]
traitEquiv[Byte]
classObject
traitMatchable
classAny
Show all
Known subtypes
objectByte
sealedtraitCachedReverse[T] extendsOrdering[T]

An ordering which caches the value of its reverse.

An ordering which caches the value of its reverse.

Attributes

Source
Ordering.scala
Supertypes
traitOrdering[T]
traitEquiv[T]
traitComparator[T]
classObject
traitMatchable
classAny
Show all
Known subtypes
objectInt
objectChar extendsCharOrdering

Attributes

Source
Ordering.scala
Supertypes
traitOrdering[Char]
traitEquiv[Char]
classObject
traitMatchable
classAny
Show all
Self type
Char.type

Attributes

Source
Ordering.scala
Supertypes
traitOrdering[Char]
traitEquiv[Char]
classObject
traitMatchable
classAny
Show all
Known subtypes
objectChar

Attributes

Source
Ordering.scala
Supertypes
traitEquiv[Double]
classObject
traitMatchable
classAny
Show all
Self type

Attributes

Source
Ordering.scala
Supertypes
traitEquiv[Float]
classObject
traitMatchable
classAny
Show all
Self type
objectDouble

Orderings forDoubles.

Orderings forDoubles.

The behavior of the comparison operations provided by the default (implicit) ordering onDouble 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 oflt,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         // -Infinityimplicitly[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
classObject
traitMatchable
classAny
Self type
Double.type

Attributes

Source
Ordering.scala
Supertypes
classObject
traitMatchable
classAny
Known subtypes
objectImplicits
objectFloat

Orderings forFloats.

Orderings forFloats.

The default extendsOrdering.Float.TotalOrdering.

Ordering.Float.TotalOrdering uses thejava.lang.Float.compare semantics for all operations. Scala also provides theOrdering.Float.IeeeOrdering semantics. Which uses the IEEE 754 semantics for float ordering.

Historically:IeeeOrdering was used in Scala from 2.10.x through 2.12.x. This changed in 2.13.0 toTotalOrdering.

Prior to Scala 2.10.0, theOrdering instance used semantics consistent withjava.lang.Float.compare.

Scala 2.10.0 changed the implementation oflt,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.

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         // -Infinityimplicitly[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
classObject
traitMatchable
classAny
Self type
Float.type

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
classObject
traitMatchable
classAny
Self type

Attributes

Source
Ordering.scala
Supertypes
traitOrdering[Int]
traitEquiv[Int]
classObject
traitMatchable
classAny
Show all
Self type
Int.type
traitIntOrdering extendsOrdering[Int]

Attributes

Source
Ordering.scala
Supertypes
traitOrdering[Int]
traitEquiv[Int]
classObject
traitMatchable
classAny
Show all
Known subtypes
objectInt
objectLong extendsLongOrdering

Attributes

Source
Ordering.scala
Supertypes
traitOrdering[Long]
traitEquiv[Long]
classObject
traitMatchable
classAny
Show all
Self type
Long.type

Attributes

Source
Ordering.scala
Supertypes
traitOrdering[Long]
traitEquiv[Long]
classObject
traitMatchable
classAny
Show all
Known subtypes
objectLong
traitOptionOrdering[T] extendsOrdering[Option[T]]

Attributes

Source
Ordering.scala
Supertypes
traitOrdering[Option[T]]
traitEquiv[Option[T]]
traitComparator[Option[T]]
classObject
traitMatchable
classAny
Show all
objectShort extendsShortOrdering

Attributes

Source
Ordering.scala
Supertypes
traitEquiv[Short]
classObject
traitMatchable
classAny
Show all
Self type
Short.type

Attributes

Source
Ordering.scala
Supertypes
traitEquiv[Short]
classObject
traitMatchable
classAny
Show all
Known subtypes
objectShort
objectString extendsStringOrdering

Attributes

Source
Ordering.scala
Supertypes
Self type
String.type

Attributes

Source
Ordering.scala
Supertypes
traitEquiv[String]
classObject
traitMatchable
classAny
Show all
Known subtypes
objectString
objectSymbol extendsSymbolOrdering

Attributes

Source
Ordering.scala
Supertypes
Self type
Symbol.type

Attributes

Source
Ordering.scala
Supertypes
traitEquiv[Symbol]
classObject
traitMatchable
classAny
Show all
Known subtypes
objectSymbol
objectUnit extendsUnitOrdering

Attributes

Source
Ordering.scala
Supertypes
traitOrdering[Unit]
traitEquiv[Unit]
classObject
traitMatchable
classAny
Show all
Self type
Unit.type

Attributes

Source
Ordering.scala
Supertypes
traitOrdering[Unit]
traitEquiv[Unit]
classObject
traitMatchable
classAny
Show all
Known subtypes
objectUnit

Inherited types

typeAsComparable[A] =A=>Comparable[_ >:A]

Attributes

Inherited from:
LowPriorityOrderingImplicits
Source
Ordering.scala

Value members

Concrete methods

defapply[T](implicitord:Ordering[T]):Ordering[T]

Attributes

Source
Ordering.scala
defby[T,S](f:T=>S)(implicitord: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
deffromLessThan[T](cmp: (T,T)=>Boolean):Ordering[T]

Construct an Ordering[T] given a functionlt.

Construct an Ordering[T] given a functionlt.

Attributes

Source
Ordering.scala

Implicits

Implicits

implicitdefOption[T](implicitord:Ordering[T]):Ordering[Option[T]]

Attributes

Source
Ordering.scala
implicitdefTuple2[T1,T2](implicitord1:Ordering[T1],ord2:Ordering[T2]):Ordering[(T1,T2)]

Attributes

Source
Ordering.scala
implicitdefTuple3[T1,T2,T3](implicitord1:Ordering[T1],ord2:Ordering[T2],ord3:Ordering[T3]):Ordering[(T1,T2,T3)]

Attributes

Source
Ordering.scala
implicitdefTuple4[T1,T2,T3,T4](implicitord1:Ordering[T1],ord2:Ordering[T2],ord3:Ordering[T3],ord4:Ordering[T4]):Ordering[(T1,T2,T3,T4)]

Attributes

Source
Ordering.scala
implicitdefTuple5[T1,T2,T3,T4,T5](implicitord1:Ordering[T1],ord2:Ordering[T2],ord3:Ordering[T3],ord4:Ordering[T4],ord5:Ordering[T5]):Ordering[(T1,T2,T3,T4,T5)]

Attributes

Source
Ordering.scala
implicitdefTuple6[T1,T2,T3,T4,T5,T6](implicitord1: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
implicitdefTuple7[T1,T2,T3,T4,T5,T6,T7](implicitord1: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
implicitdefTuple8[T1,T2,T3,T4,T5,T6,T7,T8](implicitord1: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
implicitdefTuple9[T1,T2,T3,T4,T5,T6,T7,T8,T9](implicitord1: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

implicitdefIterable[T](implicitord:Ordering[T]):Ordering[Iterable[T]]

Attributes

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)")

Iterables are not guaranteed to have a consistent order, so theOrdering returned by this method may not be stable or meaningful. If you are using a type with a consistent order (such asSeq), use itsOrdering (found in theImplicits object) instead.

Source
Ordering.scala

Inherited implicits

implicitdefcomparatorToOrdering[A](implicitcmp:Comparator[A]):Ordering[A]

Attributes

Inherited from:
LowPriorityOrderingImplicits
Source
Ordering.scala
implicitdefordered[A](implicitasComparable:A=>Comparable[_ >: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 makeOrdered[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 makeOrdered[A] => Ordering[A] only turn up if nothing else works. SinceOrdered[A] extendsComparable[A] anyway, we can throw in some Java interop too.

Attributes

Inherited from:
LowPriorityOrderingImplicits
Source
Ordering.scala
In this article
Generated with
Copyright (c) 2002-2025, LAMP/EPFL
Copyright (c) 2002-2025, LAMP/EPFL

[8]ページ先頭

©2009-2025 Movatter.jp