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

  • trait Ordering[T] extends Comparator[T] with PartialOrdering[T] with Serializable

    Ordering is a trait whose instances each represent a strategy for sorting instances of a type.

    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:

    import scala.util.Sorting
    val pairs = Array(("a", 5, 2), ("c", 3, 1), ("b", 1, 3))
    
    // sort by 2nd element
    Sorting.quickSort(pairs)(Ordering.by[(String, Int, Int), Int](_._2))
    
    // sort by the 3rd element, then 1st
    Sorting.quickSort(pairs)(Ordering[(Int, String)].on(x => (x._3, x._1)))

    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:

    import scala.util.Sorting
    
    case class Person(name:String, age:Int)
    val people = Array(Person("bob", 30), Person("ann", 32), Person("carl", 19))
    
    // sort by age
    object AgeOrdering extends Ordering[Person] {
      def compare(a:Person, b:Person) = a.age compare b.age
    }
    Sorting.quickSort(people)(AgeOrdering)

    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.

    Definition Classes
    math
    Annotations
    @implicitNotFound()
    See also

    scala.math.Ordered, scala.util.Sorting

  • OrderingOps
c

scala.math.Ordering

OrderingOps

class OrderingOps extends AnyRef

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.

Source
Ordering.scala
Linear Supertypes
Type Hierarchy
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. OrderingOps
  2. AnyRef
  3. Any
Implicitly
  1. by any2stringadd
  2. by StringFormat
  3. by Ensuring
  4. by ArrowAssoc
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Instance Constructors

  1. new OrderingOps(lhs: T)

Value Members

  1. def <(rhs: T): Boolean
  2. def <=(rhs: T): Boolean
  3. def >(rhs: T): Boolean
  4. def >=(rhs: T): Boolean
  5. def equiv(rhs: T): Boolean
  6. def max(rhs: T): T
  7. def min(rhs: T): T