Packages

  • package root

    This is the documentation for the Scala standard library.

    This is the documentation for the Scala standard library.

    Package structure

    The scala package contains core types like Int, Float, Array or Option which are accessible in all Scala compilation units without explicit qualification or imports.

    Notable packages include:

    Other packages exist. See the complete list on the right.

    Additional parts of the standard library are shipped as separate libraries. These include:

    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 for scala.collection.immutable.List.

    Other aliases refer to classes provided by the underlying platform. For example, on the JVM, String is an alias for java.lang.String.

    Definition Classes
    root
  • package scala

    Core Scala types.

    Core Scala types. They are always available without an explicit import.

    Definition Classes
    root
  • package math

    The package object scala.math contains methods for performing basic numeric operations such as elementary exponential, logarithmic, root and trigonometric functions.

    The package object scala.math contains methods for performing basic numeric operations such as elementary exponential, logarithmic, root and trigonometric functions.

    All methods forward to java.lang.Math unless otherwise noted.

    Definition Classes
    scala
    See also

    java.lang.Math

  • object Ordering extends LowPriorityOrderingImplicits with java.io.Serializable

    This is the companion object for the scala.math.Ordering 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.

    Definition Classes
    math
  • 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
    }
    Definition Classes
    Ordering
  • IeeeOrdering
  • TotalOrdering

implicit object IeeeOrdering extends IeeeOrdering

Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. IeeeOrdering
  2. IeeeOrdering
  3. Ordering
  4. PartialOrdering
  5. Equiv
  6. Serializable
  7. Comparator
  8. AnyRef
  9. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Type Members

  1. class OrderingOps extends AnyRef

    This inner class defines comparison operators available for T.

    This inner class defines comparison operators available for T.

    It can't extend AnyVal because it is not a top-level class or a member of a statically accessible object.

    Definition Classes
    Ordering

Value Members

  1. def compare(x: Double, y: Double): Int

    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:

    • negative if x < y
    • positive if x > y
    • zero otherwise (if x == y)
    Definition Classes
    IeeeOrderingOrdering → Comparator
  2. def equiv(x: Double, y: Double): Boolean

    Return true if x == y in the ordering.

    Return true if x == y in the ordering.

    Definition Classes
    IeeeOrderingOrderingPartialOrderingEquiv
  3. def gt(x: Double, y: Double): Boolean

    Return true if x > y in the ordering.

    Return true if x > y in the ordering.

    Definition Classes
    IeeeOrderingOrderingPartialOrdering
  4. def gteq(x: Double, y: Double): Boolean

    Return true if x >= y in the ordering.

    Return true if x >= y in the ordering.

    Definition Classes
    IeeeOrderingOrderingPartialOrdering
  5. def isReverseOf(other: Ordering[_]): Boolean

    Returns whether or not the other ordering is the opposite ordering of this one.

    Returns whether or not the other ordering is the opposite ordering of this one.

    Equivalent to other == this.reverse.

    Implementations should only override this method if they are overriding reverse as well.

    Definition Classes
    Ordering
  6. def lt(x: Double, y: Double): Boolean

    Return true if x < y in the ordering.

    Return true if x < y in the ordering.

    Definition Classes
    IeeeOrderingOrderingPartialOrdering
  7. def lteq(x: Double, y: Double): Boolean

    Return true if x <= y in the ordering.

    Return true if x <= y in the ordering.

    Definition Classes
    IeeeOrderingOrderingPartialOrdering
  8. def max[U <: Double](x: U, y: U): U

    Return x if x >= y, otherwise y.

    Return x if x >= y, otherwise y.

    Definition Classes
    IeeeOrderingOrdering
  9. def min[U <: Double](x: U, y: U): U

    Return x if x <= y, otherwise y.

    Return x if x <= y, otherwise y.

    Definition Classes
    IeeeOrderingOrdering
  10. implicit def mkOrderingOps(lhs: Double): OrderingOps

    This implicit method augments T with the comparison operators defined in scala.math.Ordering.Ops.

    This implicit method augments T with the comparison operators defined in scala.math.Ordering.Ops.

    Definition Classes
    Ordering
  11. def on[U](f: (U) => Double): Ordering[U]

    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))
    Definition Classes
    Ordering
  12. def orElse(other: Ordering[Double]): Ordering[Double]

    Creates an Ordering[T] whose compare function returns the result of this Ordering's compare function, if it is non-zero, or else the result of others compare function.

    Creates an Ordering[T] whose compare function returns the result of this Ordering's compare function, if it is non-zero, or else the result of others compare function.

    other

    an Ordering to use if this Ordering returns zero

    Definition Classes
    Ordering
    Example:
    1. case class Pair(a: Int, b: Int)
      
      val pairOrdering = Ordering.by[Pair, Int](_.a)
                                 .orElse(Ordering.by[Pair, Int](_.b))
  13. def orElseBy[S](f: (Double) => S)(implicit ord: Ordering[S]): Ordering[Double]

    Given f, a function from T into S, creates an Ordering[T] whose compare function returns the result of this Ordering's compare function, if it is non-zero, or else a result equivalent to:

    Given f, a function from T into S, creates an Ordering[T] whose compare function returns the result of this Ordering's compare function, if it is non-zero, or else a result equivalent to:

    Ordering[S].compare(f(x), f(y))

    This function is equivalent to passing the result of Ordering.by(f) to orElse.

    Definition Classes
    Ordering
    Example:
    1. case class Pair(a: Int, b: Int)
      
      val pairOrdering = Ordering.by[Pair, Int](_.a)
                                 .orElseBy[Int](_.b)
  14. def reverse: Ordering[Double]

    Return the opposite ordering of this one.

    Return the opposite ordering of this one.

    Implementations overriding this method MUST override isReverseOf as well if they change the behavior at all (for example, caching does not require overriding it).

    Definition Classes
    OrderingPartialOrdering
  15. def reversed(): Comparator[Double]
    Definition Classes
    Comparator
  16. def thenComparing[U <: Comparable[_ >: U <: AnyRef]](arg0: java.util.function.Function[_ >: Double <: AnyRef, _ <: U]): Comparator[Double]
    Definition Classes
    Comparator
  17. def thenComparing[U <: AnyRef](arg0: java.util.function.Function[_ >: Double <: AnyRef, _ <: U], arg1: Comparator[_ >: U <: AnyRef]): Comparator[Double]
    Definition Classes
    Comparator
  18. def thenComparing(arg0: Comparator[_ >: Double <: AnyRef]): Comparator[Double]
    Definition Classes
    Comparator
  19. def thenComparingDouble(arg0: ToDoubleFunction[_ >: Double <: AnyRef]): Comparator[Double]
    Definition Classes
    Comparator
  20. def thenComparingInt(arg0: ToIntFunction[_ >: Double <: AnyRef]): Comparator[Double]
    Definition Classes
    Comparator
  21. def thenComparingLong(arg0: ToLongFunction[_ >: Double <: AnyRef]): Comparator[Double]
    Definition Classes
    Comparator
  22. def tryCompare(x: Double, y: Double): Some[Int]

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

    Definition Classes
    OrderingPartialOrdering