scala

package scala

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

Attributes

Members list

Packages

package scala.beans
package scala.compat

This package object contains primitives for concurrent and parallel programming.

This package object contains primitives for concurrent and parallel programming.

Guide

A more detailed guide to Futures and Promises, including discussion and examples can be found at https://docs.scala-lang.org/overviews/core/futures.html.

Common Imports

When working with Futures, you will often find that importing the whole concurrent package is convenient:

import scala.concurrent._

When using things like Futures, it is often required to have an implicit ExecutionContext in scope. The general advice for these implicits are as follows.

If the code in question is a class or method definition, and no ExecutionContext is available, request one from the caller by adding an implicit parameter list:

def myMethod(myParam: MyType)(implicit ec: ExecutionContext) = …
//Or
class MyClass(myParam: MyType)(implicit ec: ExecutionContext) { … }

This allows the caller of the method, or creator of the instance of the class, to decide which ExecutionContext should be used.

For typical REPL usage and experimentation, importing the global ExecutionContext is often desired.

import scala.concurrent.ExcutionContext.Implicits.global

Specifying Durations

Operations often require a duration to be specified. A duration DSL is available to make defining these easier:

import scala.concurrent.duration._
val d: Duration = 10.seconds

Using Futures For Non-blocking Computation

Basic use of futures is easy with the factory method on Future, which executes a provided function asynchronously, handing you back a future result of that function without blocking the current thread. In order to create the Future you will need either an implicit or explicit ExecutionContext to be provided:

import scala.concurrent._
import ExecutionContext.Implicits.global  // implicit execution context

val firstZebra: Future[Int] = Future {
 val words = Files.readAllLines("/etc/dictionaries-common/words").asScala
 words.indexOfSlice("zebra")
}

Avoid Blocking

Although blocking is possible in order to await results (with a mandatory timeout duration):

import scala.concurrent.duration._
Await.result(firstZebra, 10.seconds)

and although this is sometimes necessary to do, in particular for testing purposes, blocking in general is discouraged when working with Futures and concurrency in order to avoid potential deadlocks and improve performance. Instead, use callbacks or combinators to remain in the future domain:

val animalRange: Future[Int] = for {
 aardvark <- firstAardvark
 zebra <- firstZebra
} yield zebra - aardvark

animalRange.onSuccess {
 case x if x > 500000 => println("It's a long way from Aardvark to Zebra")
}

Attributes

package scala.deriving
package scala.io
package scala.jdk

The jdk package contains utilities to interact with JDK classes.

The jdk package contains utilities to interact with JDK classes.

This packages offers a number of converters, that are able to wrap or copy types from the scala library to equivalent types in the JDK class library and vice versa:

- CollectionConverters, converting collections like scala.collection.Seq, scala.collection.Map, scala.collection.Set, scala.collection.mutable.Buffer, scala.collection.Iterator and scala.collection.Iterable to their JDK counterparts - OptionConverters, converting between Option and java.util.Optional and primitive variations - StreamConverters, to create JDK Streams from scala collections - DurationConverters, for conversions between scala scala.concurrent.duration.FiniteDuration and java.time.Duration - FunctionConverters, from scala Functions to java java.util.function.Function, java.util.function.UnaryOperator, java.util.function.Consumer and java.util.function.Predicate, as well as primitive variations and Bi-variations.

By convention, converters that wrap an object to provide a different interface to the same underlying data structure use .asScala and .asJava extension methods, whereas converters that copy the underlying data structure use .toScala and .toJava.

In the javaapi package, the same converters can be found with a java-friendly interface that don't rely on implicit enrichments.

Additionally, this package offers Accumulators, capable of efficiently traversing JDK Streams.

Attributes

package scala.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.

Attributes

See also
package scala.quoted
package scala.ref
package scala.reflect
package scala.runtime
package scala.sys

The package object scala.sys contains methods for reading and altering core aspects of the virtual machine as well as the world outside of it.

The package object scala.sys contains methods for reading and altering core aspects of the virtual machine as well as the world outside of it.

Attributes

package scala.util

Type members

Classlikes

object #::

Attributes

Source
package.scala
Supertypes
class Object
trait Matchable
class Any
Self type
#::.type
sealed abstract class *:[+H, +T <: Tuple] extends NonEmptyTuple

Attributes

Companion
object
Source
Tuple.scala
Supertypes
trait Tuple
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
object *:

Attributes

Companion
class
Source
Tuple.scala
Supertypes
trait Sum
trait Mirror
class Object
trait Matchable
class Any
Self type
*:.type
sealed abstract class <:<[-From, +To] extends From => To, Serializable

An instance of A <:< B witnesses that A is a subtype of B.

An instance of A <:< B witnesses that A is a subtype of B. Requiring an implicit argument of the type A <:< B encodes the generalized constraint A <: B.

To constrain any abstract type T that's in scope in a method's argument list (not just the method's own type parameters) simply add an implicit argument of type T <:< U, where U is the required upper bound; or for lower-bounds, use: L <:< T, where L is the required lower bound.

In case of any confusion over which method goes in what direction, all the "Co" methods (including apply) go from left to right in the type ("with" the type), and all the "Contra" methods go from right to left ("against" the type). E.g., apply turns a From into a To, and substituteContra replaces the Tos in a type with Froms.

In part contributed by Jason Zaugg.

Type parameters

From

a type which is proved a subtype of To

To

a type which is proved a supertype of From

Attributes

See also

=:= for expressing equality constraints

Example

scala.Option#flatten

sealed trait Option[+A] {
  // def flatten[B, A <: Option[B]]: Option[B] = ...
  // won't work, since the A in flatten shadows the class-scoped A.
  def flatten[B](implicit ev: A <:< Option[B]): Option[B]
    = if(isEmpty) None else ev(get)
  // Because (A <:< Option[B]) <: (A => Option[B]), ev can be called to turn the
  // A from get into an Option[B], and because ev is implicit, that call can be
  // left out and inserted automatically.
}
Companion
object
Source
typeConstraints.scala
Supertypes
trait Serializable
trait From => To
class Object
trait Matchable
class Any
Known subtypes
class From =:= To
object <:<

Attributes

Companion
class
Source
typeConstraints.scala
Supertypes
class Object
trait Matchable
class Any
Self type
<:<.type
sealed abstract class =:=[From, To] extends From <:< To, Serializable

An instance of A =:= B witnesses that the types A and B are equal.

An instance of A =:= B witnesses that the types A and B are equal. It also acts as a A <:< B, but not a B <:< A (directly) due to restrictions on subclassing.

In case of any confusion over which method goes in what direction, all the "Co" methods (including apply) go from left to right in the type ("with" the type), and all the "Contra" methods go from right to left ("against" the type). E.g., apply turns a From into a To, and substituteContra replaces the Tos in a type with Froms.

Type parameters

From

a type which is proved equal to To

To

a type which is proved equal to From

Attributes

See also

<:< for expressing subtyping constraints

Example

An in-place variant of scala.collection.mutable.ArrayBuffer#transpose

implicit class BufOps[A](private val buf: ArrayBuffer[A]) extends AnyVal {
  def inPlaceTranspose[E]()(implicit ev: A =:= ArrayBuffer[E]) = ???
  // Because ArrayBuffer is invariant, we can't make do with just a A <:< ArrayBuffer[E]
  // Getting buffers *out* from buf would work, but adding them back *in* wouldn't.
}
Source
typeConstraints.scala
Supertypes
class From <:< To
trait Serializable
trait From => To
class Object
trait Matchable
class Any
Show all
abstract open class Any

Class Any is the root of the Scala class hierarchy.

Class Any is the root of the Scala class hierarchy. Every class in a Scala execution environment inherits directly or indirectly from this class.

Starting with Scala 2.10 it is possible to directly extend Any using universal traits. A universal trait is a trait that extends Any, only has defs as members, and does no initialization.

The main use case for universal traits is to allow basic inheritance of methods for value classes. For example,

trait Printable extends Any {
  def print(): Unit = println(this)
}
class Wrapper(val underlying: Int) extends AnyVal with Printable

val w = new Wrapper(3)
w.print()

See the Value Classes and Universal Traits for more details on the interplay of universal traits and value classes.

Attributes

final abstract class AnyKind

The super-type of all types.

class AnyRef

Class AnyRef is the root class of all reference types.

Class AnyRef is the root class of all reference types. All types except the value types descend from this class.

Attributes

Known subtypes
trait () => R
class FromJavaSupplier[T]
trait Reference[T]
trait ReferenceWrapper[T]
class PhantomReference[T]
class SoftReference[T]
class WeakReference[T]
trait T1 => R
trait SetOps[A, CC, C]
trait SetOps[A, CC, C]
trait Set[A]
class AbstractSet[A]
class BitSet
class BitSet1
class BitSet2
class BitSetN
class HashSet[A]
class ListSet[A]
class Set1[A]
class Set2[A]
class Set3[A]
class Set4[A]
class TreeSet[A]
class ValueSet
trait SortedSet[A]
trait SortedSetOps[A, CC, C]
trait StrictOptimizedSortedSetOps[A, CC, C]
trait StrictOptimizedSetOps[A, CC, C]
trait SetOps[A, CC, C]
class HashSet[A]
class LinkedHashSet[A]
trait Set[A]
class AbstractSet[A]
class BitSet
class TreeSet[A]
trait SortedSet[A]
trait SortedSetOps[A, CC, C]
trait Set[A]
class AbstractSet[A]
trait SortedSet[A]
trait BitSet
trait SortedSetOps[A, CC, C]
trait BitSetOps[C]
trait SortedSetFactoryDefaults[A, CC, WithFilterCC]
trait StrictOptimizedSortedSetOps[A, CC, C]
trait StrictOptimizedSetOps[A, CC, C]
class FromJavaConsumer[T]
class FromJavaFunction[T, R]
class AbstractFunction1[T1, R]
class From <:< To
class From =:= To
class Conversion[T, U]
trait PartialFunction[A, B]
trait MapOps[K, V, CC, C]
trait MapOps[K, V, CC, C]
trait Map[K, V]
class AbstractMap[K, V]
class HashMap[K, V]
class IntMap[T]
class ListMap[K, V]
class LongMap[T]
class Map1[K, V]
class Map2[K, V]
class Map3[K, V]
class Map4[K, V]
class WithDefault[K, V]
class WithDefault[K, V]
class TreeMap[K, V]
class TreeSeqMap[K, V]
class VectorMap[K, V]
trait SeqMap[K, V]
trait SortedMap[K, V]
trait SortedMapOps[K, V, CC, C]
trait StrictOptimizedSortedMapOps[K, V, CC, C]
trait StrictOptimizedMapOps[K, V, CC, C]
trait MapOps[K, V, CC, C]
class TrieMap[K, V]
class AnyRefMap[K, V]
class CollisionProofHashMap[K, V]
class HashMap[K, V]
class LinkedHashMap[K, V]
class ListMap[K, V]
class LongMap[V]
trait Map[K, V]
trait Map[K, V]
class AbstractMap[K, V]
class WithDefault[K, V]
class WithDefault[K, V]
class OpenHashMap[Key, Value]
class TreeMap[K, V]
trait MultiMap[K, V]
trait SeqMap[K, V]
trait SortedMap[K, V]
trait SortedMapOps[K, V, CC, C]
trait Map[K, V]
class AbstractMap[K, V]
trait DefaultMap[K, V]
trait SeqMap[K, V]
trait SortedMap[K, V]
trait MapFactoryDefaults[K, V, CC, WithFilterCC]
class WeakHashMap[K, V]
trait MapView[K, V]
class AbstractMapView[K, V]
class Filter[K, V]
class FilterKeys[K, V]
class Id[K, V]
class MapValues[K, V, W]
class TapEach[K, V, U]
trait SortedMapFactoryDefaults[K, V, CC, WithFilterCC, UnsortedCC]
trait SortedMapOps[K, V, CC, C]
trait StrictOptimizedSortedMapOps[K, V, CC, C]
trait StrictOptimizedMapOps[K, V, CC, C]
trait Seq[A]
trait Seq[A]
class AbstractSeq[A]
class ArraySeq[A]
class ofBoolean
class ofByte
class ofChar
class ofDouble
class ofFloat
class ofInt
class ofLong
class ofRef[T]
class ofShort
class ofUnit
class LazyList[A]
class List[A]
class ::[A]
object Nil.type
class NumericRange[T]
class Exclusive[T]
class Inclusive[T]
class Queue[A]
class Range
class Exclusive
class Inclusive
class Stream[A]
class Cons[A]
object Empty.type
class Vector[A]
trait IndexedSeq[A]
trait LinearSeq[A]
trait Seq[A]
class AbstractSeq[A]
class AbstractBuffer[A]
class ArrayBuffer[A]
class ArrayDeque[A]
class Queue[A]
class Stack[A]
class ListBuffer[A]
class UnrolledBuffer[T]
class ArraySeq[T]
class ofBoolean
class ofByte
class ofChar
class ofDouble
class ofFloat
class ofInt
class ofLong
class ofRef[T]
class ofShort
class ofUnit
trait Buffer[A]
trait IndexedBuffer[A]
trait IndexedSeq[T]
class Accumulator[A, CC, C]
class AnyAccumulator[A]
class AbstractSeq[A]
trait IndexedSeq[A]
trait LinearSeq[A]
trait (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10) => R
class AbstractFunction10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, R]
trait (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11) => R
class AbstractFunction11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, R]
trait (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12) => R
class AbstractFunction12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, R]
trait (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13) => R
class AbstractFunction13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, R]
trait (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14) => R
class AbstractFunction14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, R]
trait (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15) => R
class AbstractFunction15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, R]
trait (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16) => R
class AbstractFunction16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, R]
trait (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17) => R
class AbstractFunction17[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, R]
trait (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18) => R
class AbstractFunction18[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, R]
trait (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19) => R
class AbstractFunction19[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, R]
trait (T1, T2) => R
class FromJavaBiConsumer[T, U]
class FromJavaBiFunction[T, U, R]
class FromJavaBiPredicate[T, U]
class AbstractFunction2[T1, T2, R]
trait (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20) => R
class AbstractFunction20[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, R]
trait (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21) => R
class AbstractFunction21[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, R]
trait (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22) => R
class AbstractFunction22[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, R]
trait (T1, T2, T3) => R
class AbstractFunction3[T1, T2, T3, R]
trait (T1, T2, T3, T4) => R
class AbstractFunction4[T1, T2, T3, T4, R]
trait (T1, T2, T3, T4, T5) => R
class AbstractFunction5[T1, T2, T3, T4, T5, R]
trait (T1, T2, T3, T4, T5, T6) => R
class AbstractFunction6[T1, T2, T3, T4, T5, T6, R]
trait (T1, T2, T3, T4, T5, T6, T7) => R
class AbstractFunction7[T1, T2, T3, T4, T5, T6, T7, R]
trait (T1, T2, T3, T4, T5, T6, T7, T8) => R
class AbstractFunction8[T1, T2, T3, T4, T5, T6, T7, T8, R]
trait (T1, T2, T3, T4, T5, T6, T7, T8, T9) => R
class AbstractFunction9[T1, T2, T3, T4, T5, T6, T7, T8, T9, R]
Show all
abstract open class AnyVal

AnyVal is the root class of all value types, which describe values not implemented as objects in the underlying host system.

AnyVal is the root class of all value types, which describe values not implemented as objects in the underlying host system. Value classes are specified in Scala Language Specification, section 12.2.

The standard implementation includes nine AnyVal subtypes:

scala.Double, scala.Float, scala.Long, scala.Int, scala.Char, scala.Short, and scala.Byte are the numeric value types.

scala.Unit and scala.Boolean are the non-numeric value types.

Other groupings:

Prior to Scala 2.10, AnyVal was a sealed trait. Beginning with Scala 2.10, however, it is possible to define a subclass of AnyVal called a user-defined value class which is treated specially by the compiler. Properly-defined user value classes provide a way to improve performance on user-defined types by avoiding object allocation at runtime, and by replacing virtual method invocations with static method invocations.

User-defined value classes which avoid object allocation...

  • must have a single val parameter that is the underlying runtime representation.

  • can define defs, but no vals, vars, or nested traitss, classes or objects.

  • typically extend no other trait apart from AnyVal.

  • cannot be used in type tests or pattern matching.

  • may not override equals or hashCode methods.

A minimal example:

class Wrapper(val underlying: Int) extends AnyVal {
  def foo: Wrapper = new Wrapper(underlying * 19)
}

It's important to note that user-defined value classes are limited, and in some circumstances, still must allocate a value class instance at runtime. These limitations and circumstances are explained in greater detail in the Value Classes and Universal Traits.

Attributes

Supertypes
trait Matchable
class Any
Known subtypes
class Deferrer[A]
class Partial[T, U]
class Deferrer[A]
class UnwrapOp
class ArrayOps[A]
class SearchImpl[Repr, A]
class Shape
class StringOps
class DoubleMult
class DurationInt
class DurationLong
class IntMult
class LongMult
class RichBiFunctionAsFunction2[T, U, R]
class RichFunction2AsBiFunction[T, U, R]
class FutureOps[T]
class RichOption[A]
class RichOptional[A]
class RichBoolean
class RichByte
class RichChar
class RichDouble
class RichFloat
class RichInt
class RichLong
class RichShort
class Tuple2Zipped[El1, It1, El2, It2]
class Ops[T1, T2]
class Tuple3Zipped[El1, It1, El2, It2, El3, It3]
class Ops[T1, T2, T3]
class ChainingOps[A]
class MergeableEither[A]
class Boolean
class Byte
class Char
class Double
class Float
class UnliftOps[A, B]
class Int
class Long
class ElementWiseExtractor[A, B]
class ArrowAssoc[A]
class Ensuring[A]
class StringFormat[A]
class any2stringadd[A]
class Short
class Unit
class ValueOf[T]
class Addr
class NameRef
Show all
trait App extends DelayedInit

The App trait can be used to quickly turn objects into executable programs.

The App trait can be used to quickly turn objects into executable programs. Here is an example:

object Main extends App {
  Console.println("Hello World: " + (args mkString ", "))
}

No explicit main method is needed. Instead, the whole class body becomes the “main method”.

args returns the current command line arguments as an array.

Caveats

It should be noted that this trait is implemented using the DelayedInit functionality, which means that fields of the object will not have been initialized before the main method has been executed.

Future versions of this trait will no longer extend DelayedInit.

In Scala 3, the DelayedInit feature was dropped. App exists only in a limited form that also does not support command line arguments and will be deprecated in the future.

@main methods are the recommended scheme to generate programs that can be invoked from the command line in Scala 3.

@main def runMyProgram(args: String*): Unit = {
  // your program here
}

If programs need to cross-build between Scala 2 and Scala 3, it is recommended to use an explicit main method:

object Main {
  def main(args: Array[String]): Unit = {
    // your program here
  }
}

Attributes

Source
App.scala
Supertypes
trait DelayedInit
class Object
trait Matchable
class Any
object Array

Utility methods for operating on arrays.

Utility methods for operating on arrays. For example:

val a = Array(1, 2)
val b = Array.ofDim[Int](2)
val c = Array.concat(a, b)

where the array objects a, b and c have respectively the values Array(1, 2), Array(0, 0) and Array(1, 2, 0, 0).

Attributes

Companion
class
Source
Array.scala
Supertypes
class Object
trait Matchable
class Any
Self type
Array.type
final class Array[T](_length: Int) extends Serializable, Cloneable

Arrays are mutable, indexed collections of values.

Arrays are mutable, indexed collections of values. Array[T] is Scala's representation for Java's T[].

val numbers = Array(1, 2, 3, 4)
val first = numbers(0) // read the first element
numbers(3) = 100 // replace the 4th array element with 100
val biggerNumbers = numbers.map(_ * 2) // multiply all numbers by two

Arrays make use of two common pieces of Scala syntactic sugar, shown on lines 2 and 3 of the above example code. Line 2 is translated into a call to apply(Int), while line 3 is translated into a call to update(Int, T).

Two implicit conversions exist in scala.Predef that are frequently applied to arrays: a conversion to scala.collection.ArrayOps (shown on line 4 of the example above) and a conversion to scala.collection.mutable.ArraySeq (a subtype of scala.collection.Seq). Both types make available many of the standard operations found in the Scala collections API. The conversion to ArrayOps is temporary, as all operations defined on ArrayOps return an Array, while the conversion to ArraySeq is permanent as all operations return a ArraySeq.

The conversion to ArrayOps takes priority over the conversion to ArraySeq. For instance, consider the following code:

val arr = Array(1, 2, 3)
val arrReversed = arr.reverse
val seqReversed : collection.Seq[Int] = arr.reverse

Value arrReversed will be of type Array[Int], with an implicit conversion to ArrayOps occurring to perform the reverse operation. The value of seqReversed, on the other hand, will be computed by converting to ArraySeq first and invoking the variant of reverse that returns another ArraySeq.

Attributes

See also

Scala Language Specification, for in-depth information on the transformations the Scala compiler makes on Arrays (Sections 6.6 and 6.15 respectively.)

"Scala 2.8 Arrays" the Scala Improvement Document detailing arrays since Scala 2.8.

"The Scala 2.8 Collections' API" section on Array by Martin Odersky for more information.

Companion
object
Source
Array.scala
Supertypes
trait Cloneable
trait Serializable
class Object
trait Matchable
class Any
final abstract class Boolean extends AnyVal

Boolean (equivalent to Java's boolean primitive type) is a subtype of scala.AnyVal.

Boolean (equivalent to Java's boolean primitive type) is a subtype of scala.AnyVal. Instances of Boolean are not represented by an object in the underlying runtime system.

There is an implicit conversion from scala.Boolean => scala.runtime.RichBoolean which provides useful non-primitive operations.

Attributes

Companion
object
Source
Boolean.scala
Supertypes
class AnyVal
trait Matchable
class Any
object Boolean

Attributes

Companion
class
Source
Boolean.scala
Supertypes
class Object
trait Matchable
class Any
Self type
Boolean.type
final abstract class Byte extends AnyVal

Byte, a 8-bit signed integer (equivalent to Java's byte primitive type) is a subtype of scala.AnyVal.

Byte, a 8-bit signed integer (equivalent to Java's byte primitive type) is a subtype of scala.AnyVal. Instances of Byte are not represented by an object in the underlying runtime system.

There is an implicit conversion from scala.Byte => scala.runtime.RichByte which provides useful non-primitive operations.

Attributes

Companion
object
Source
Byte.scala
Supertypes
class AnyVal
trait Matchable
class Any
object Byte

Attributes

Companion
class
Source
Byte.scala
Supertypes
class Object
trait Matchable
class Any
Self type
Byte.type
sealed trait CanEqual[-L, -R]

A marker trait indicating that values of type L can be compared to values of type R.

A marker trait indicating that values of type L can be compared to values of type R.

Attributes

Companion
object
Source
CanEqual.scala
Supertypes
class Object
trait Matchable
class Any
Known subtypes
object derived.type
object CanEqual

Companion object containing a few universally known CanEqual instances. CanEqual instances involving primitive types or the Null type are handled directly in the compiler (see Implicits.synthesizedCanEqual), so they are not included here.

Companion object containing a few universally known CanEqual instances. CanEqual instances involving primitive types or the Null type are handled directly in the compiler (see Implicits.synthesizedCanEqual), so they are not included here.

Attributes

Companion
trait
Source
CanEqual.scala
Supertypes
trait Sum
trait Mirror
class Object
trait Matchable
class Any
Self type
CanEqual.type
final abstract class Char extends AnyVal

Char, a 16-bit unsigned integer (equivalent to Java's char primitive type) is a subtype of scala.AnyVal.

Char, a 16-bit unsigned integer (equivalent to Java's char primitive type) is a subtype of scala.AnyVal. Instances of Char are not represented by an object in the underlying runtime system.

There is an implicit conversion from scala.Char => scala.runtime.RichChar which provides useful non-primitive operations.

Attributes

Companion
object
Source
Char.scala
Supertypes
class AnyVal
trait Matchable
class Any
object Char

Attributes

Companion
class
Source
Char.scala
Supertypes
class Object
trait Matchable
class Any
Self type
Char.type
object Console extends AnsiColor

Implements functionality for printing Scala values on the terminal.

Implements functionality for printing Scala values on the terminal. For reading values use StdIn. Also defines constants for marking up text on ANSI terminals.

Console Output

Use the print methods to output text.

scala> Console.printf(
  "Today the outside temperature is a balmy %.1f°C. %<.1f°C beats the previous record of %.1f°C.\n",
  -137.0,
  -135.05)
Today the outside temperature is a balmy -137.0°C. -137.0°C beats the previous record of -135.1°C.

ANSI escape codes

Use the ANSI escape codes for colorizing console output either to STDOUT or STDERR.

import Console.{GREEN, RED, RESET, YELLOW_B, UNDERLINED}

object PrimeTest {

  def isPrime(): Unit = {

    val candidate = io.StdIn.readInt().ensuring(_ > 1)

    val prime = (2 to candidate - 1).forall(candidate % _ != 0)

    if (prime)
      Console.println(s"${RESET}${GREEN}yes${RESET}")
    else
      Console.err.println(s"${RESET}${YELLOW_B}${RED}${UNDERLINED}NO!${RESET}")
  }

  def main(args: Array[String]): Unit = isPrime()

}

$ scala PrimeTest
1234567891
yes
$ scala PrimeTest
56474
NO!

IO redefinition

Use IO redefinition to temporarily swap in a different set of input and/or output streams. In this example the stream based method above is wrapped into a function.

import java.io.{ByteArrayOutputStream, StringReader}

object FunctionalPrimeTest {

  def isPrime(candidate: Int): Boolean = {

    val input = new StringReader(s"$candidate\n")
    val outCapture = new ByteArrayOutputStream
    val errCapture = new ByteArrayOutputStream

    Console.withIn(input) {
      Console.withOut(outCapture) {
        Console.withErr(errCapture) {
          PrimeTest.isPrime()
        }
      }
    }

    if (outCapture.toByteArray.nonEmpty) // "yes"
      true
    else if (errCapture.toByteArray.nonEmpty) // "NO!"
      false
    else throw new IllegalArgumentException(candidate.toString)
  }

  def main(args: Array[String]): Unit = {
    val primes = (2 to 50) filter (isPrime)
    println(s"First primes: $primes")
  }

}

$ scala FunctionalPrimeTest
First primes: Vector(2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47)

Attributes

Source
Console.scala
Supertypes
trait AnsiColor
class Object
trait Matchable
class Any
Self type
Console.type
abstract class Conversion[-T, +U] extends T => U

A class for implicit values that can serve as implicit conversions. The implicit resolution algorithm will act as if there existed the additional implicit definition:

A class for implicit values that can serve as implicit conversions. The implicit resolution algorithm will act as if there existed the additional implicit definition:

def $implicitConversion[T, U](x: T)(c: Conversion[T, U]): U = c(x)

However, the presence of this definition would slow down implicit search since its outermost type matches any pair of types. Therefore, implicit search contains a special case in Implicits#discardForView which emulates the conversion in a more efficient way.

Note that this is a SAM class - function literals are automatically converted to the Conversion values.

Also note that in bootstrapped dotty, Predef.<:< should inherit from Conversion. This would cut the number of special cases in discardForView from two to one.

The Conversion class can also be used to convert explicitly, using the convert extension method.

Attributes

Source
Conversion.scala
Supertypes
trait T => U
class Object
trait Matchable
class Any
final abstract class Double extends AnyVal

Double, a 64-bit IEEE-754 floating point number (equivalent to Java's double primitive type) is a subtype of scala.AnyVal.

Double, a 64-bit IEEE-754 floating point number (equivalent to Java's double primitive type) is a subtype of scala.AnyVal. Instances of Double are not represented by an object in the underlying runtime system.

There is an implicit conversion from scala.Double => scala.runtime.RichDouble which provides useful non-primitive operations.

Attributes

Companion
object
Source
Double.scala
Supertypes
class AnyVal
trait Matchable
class Any
object Double

Attributes

Companion
class
Source
Double.scala
Supertypes
class Object
trait Matchable
class Any
Self type
Double.type
final class DummyImplicit

A type for which there is always an implicit value.

A type for which there is always an implicit value.

Attributes

Companion
object
Source
DummyImplicit.scala
Supertypes
class Object
trait Matchable
class Any
object DummyImplicit

Attributes

Companion
class
Source
DummyImplicit.scala
Supertypes
class Object
trait Matchable
class Any
Self type
trait Dynamic

A marker trait that enables dynamic invocations.

A marker trait that enables dynamic invocations. Instances x of this trait allow method invocations x.meth(args) for arbitrary method names meth and argument lists args as well as field accesses x.field for arbitrary field names field.

If a call is not natively supported by x (i.e. if type checking fails), it is rewritten according to the following rules:

foo.method("blah")      ~~> foo.applyDynamic("method")("blah")
foo.method(x = "blah")  ~~> foo.applyDynamicNamed("method")(("x", "blah"))
foo.method(x = 1, 2)    ~~> foo.applyDynamicNamed("method")(("x", 1), ("", 2))
foo.field           ~~> foo.selectDynamic("field")
foo.varia = 10      ~~> foo.updateDynamic("varia")(10)
foo.arr(10) = 13    ~~> foo.selectDynamic("arr").update(10, 13)
foo.arr(10)         ~~> foo.applyDynamic("arr")(10)

As of Scala 2.10, defining direct or indirect subclasses of this trait is only possible if the language feature dynamics is enabled.

Attributes

Source
Dynamic.scala
Supertypes
class Any
case object EmptyTuple extends Tuple

A tuple of 0 elements.

A tuple of 0 elements.

Attributes

Source
Tuple.scala
Supertypes
trait Singleton
trait Product
trait Mirror
trait Serializable
trait Tuple
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
Self type
EmptyTuple.type
abstract class Enumeration(initial: Int) extends Serializable

Defines a finite set of values specific to the enumeration.

Defines a finite set of values specific to the enumeration. Typically these values enumerate all possible forms something can take and provide a lightweight alternative to case classes.

Each call to a Value method adds a new unique value to the enumeration. To be accessible, these values are usually defined as val members of the enumeration.

All values in an enumeration share a common, unique type defined as the Value type member of the enumeration (Value selected on the stable identifier path of the enumeration instance).

Values SHOULD NOT be added to an enumeration after its construction; doing so makes the enumeration thread-unsafe. If values are added to an enumeration from multiple threads (in a non-synchronized fashion) after construction, the behavior of the enumeration is undefined.

Value parameters

initial

The initial value from which to count the integers that identifies values at run-time.

Attributes

Example

// Define a new enumeration with a type alias and work with the full set of enumerated values
object WeekDay extends Enumeration {
 type WeekDay = Value
 val Mon, Tue, Wed, Thu, Fri, Sat, Sun = Value
}
import WeekDay._
def isWorkingDay(d: WeekDay) = ! (d == Sat || d == Sun)
WeekDay.values filter isWorkingDay foreach println
// output:
// Mon
// Tue
// Wed
// Thu
// Fri

// Example of adding attributes to an enumeration by extending the Enumeration.Val class
object Planet extends Enumeration {
 protected case class PlanetVal(mass: Double, radius: Double) extends super.Val {
   def surfaceGravity: Double = Planet.G * mass / (radius * radius)
   def surfaceWeight(otherMass: Double): Double = otherMass * surfaceGravity
 }
 import scala.language.implicitConversions
 implicit def valueToPlanetVal(x: Value): PlanetVal = x.asInstanceOf[PlanetVal]
 val G: Double = 6.67300E-11
 val Mercury = PlanetVal(3.303e+23, 2.4397e6)
 val Venus   = PlanetVal(4.869e+24, 6.0518e6)
 val Earth   = PlanetVal(5.976e+24, 6.37814e6)
 val Mars    = PlanetVal(6.421e+23, 3.3972e6)
 val Jupiter = PlanetVal(1.9e+27, 7.1492e7)
 val Saturn  = PlanetVal(5.688e+26, 6.0268e7)
 val Uranus  = PlanetVal(8.686e+25, 2.5559e7)
 val Neptune = PlanetVal(1.024e+26, 2.4746e7)
}
println(Planet.values.filter(_.radius > 7.0e6))
// output:
// Planet.ValueSet(Jupiter, Saturn, Uranus, Neptune)
Source
Enumeration.scala
Supertypes
trait Serializable
class Object
trait Matchable
class Any
Known subtypes
object RoundingMode.type
Self type
trait Equals

An interface containing operations for equality.

An interface containing operations for equality. The only method not already present in class AnyRef is canEqual.

Attributes

Source
Equals.scala
Supertypes
class Any
Known subtypes
trait Map[K, V]
trait Map[K, V]
class AbstractMap[K, V]
class HashMap[K, V]
class IntMap[T]
class ListMap[K, V]
class LongMap[T]
class Map1[K, V]
class Map2[K, V]
class Map3[K, V]
class Map4[K, V]
class WithDefault[K, V]
class WithDefault[K, V]
class TreeMap[K, V]
class TreeSeqMap[K, V]
class VectorMap[K, V]
trait SeqMap[K, V]
trait SortedMap[K, V]
trait Map[K, V]
trait Map[K, V]
class TrieMap[K, V]
class AbstractMap[K, V]
class AnyRefMap[K, V]
class CollisionProofHashMap[K, V]
class HashMap[K, V]
class LinkedHashMap[K, V]
class ListMap[K, V]
class LongMap[V]
class WithDefault[K, V]
class WithDefault[K, V]
class OpenHashMap[Key, Value]
class TreeMap[K, V]
trait MultiMap[K, V]
trait SeqMap[K, V]
trait SortedMap[K, V]
class AbstractMap[K, V]
trait DefaultMap[K, V]
trait SeqMap[K, V]
trait SortedMap[K, V]
trait Seq[A]
trait Seq[A]
class AbstractSeq[A]
class ArraySeq[A]
class ofBoolean
class ofByte
class ofChar
class ofDouble
class ofFloat
class ofInt
class ofLong
class ofRef[T]
class ofShort
class ofUnit
class LazyList[A]
class List[A]
class ::[A]
object Nil.type
class NumericRange[T]
class Exclusive[T]
class Inclusive[T]
class Queue[A]
class Range
class Exclusive
class Inclusive
class Stream[A]
class Cons[A]
object Empty.type
class Vector[A]
trait IndexedSeq[A]
trait LinearSeq[A]
trait Seq[A]
class AbstractSeq[A]
class AbstractBuffer[A]
class ArrayBuffer[A]
class ArrayDeque[A]
class Queue[A]
class Stack[A]
class ListBuffer[A]
class UnrolledBuffer[T]
class ArraySeq[T]
class ofBoolean
class ofByte
class ofChar
class ofDouble
class ofFloat
class ofInt
class ofLong
class ofRef[T]
class ofShort
class ofUnit
trait Buffer[A]
trait IndexedBuffer[A]
trait IndexedSeq[T]
class Accumulator[A, CC, C]
class AnyAccumulator[A]
class AbstractSeq[A]
trait IndexedSeq[A]
trait LinearSeq[A]
trait Set[A]
trait Set[A]
class AbstractSet[A]
class BitSet
class BitSet1
class BitSet2
class BitSetN
class HashSet[A]
class ListSet[A]
class Set1[A]
class Set2[A]
class Set3[A]
class Set4[A]
class TreeSet[A]
class ValueSet
trait SortedSet[A]
trait Set[A]
class AbstractSet[A]
class BitSet
class HashSet[A]
class LinkedHashSet[A]
class TreeSet[A]
trait SortedSet[A]
class AbstractSet[A]
trait SortedSet[A]
trait BitSet
class AnyValManifest[T]
trait ClassTag[T]
trait Manifest[T]
trait Product
trait Enum
trait EnumValue
class TupleXXL
class Either[A, B]
class Left[A, B]
class Right[A, B]
class Try[T]
class Failure[T]
class Success[T]
class Option[A]
object None.type
class Some[A]
trait Product1[T1]
class (T1)
trait Product10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]
class (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10)
trait Product11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11]
class (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11)
trait Product12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12]
class (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12)
trait Product13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13]
class (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13)
trait Product14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14]
class (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14)
trait Product15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15]
class (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15)
trait Product16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16]
class (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16)
trait Product17[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17]
class (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17)
trait Product18[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18]
class (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18)
trait Product19[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19]
class (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19)
trait Product2[T1, T2]
class (T1, T2)
trait Product20[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20]
class (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20)
trait Product21[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21]
class (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21)
trait Product22[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22]
class (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22)
trait Product3[T1, T2, T3]
class (T1, T2, T3)
trait Product4[T1, T2, T3, T4]
class (T1, T2, T3, T4)
trait Product5[T1, T2, T3, T4, T5]
class (T1, T2, T3, T4, T5)
trait Product6[T1, T2, T3, T4, T5, T6]
class (T1, T2, T3, T4, T5, T6)
trait Product7[T1, T2, T3, T4, T5, T6, T7]
class (T1, T2, T3, T4, T5, T6, T7)
trait Product8[T1, T2, T3, T4, T5, T6, T7, T8]
class (T1, T2, T3, T4, T5, T6, T7, T8)
trait Product9[T1, T2, T3, T4, T5, T6, T7, T8, T9]
class (T1, T2, T3, T4, T5, T6, T7, T8, T9)
trait Tuple
object EmptyTuple.type
class H *: T
Show all
final abstract class Float extends AnyVal

Float, a 32-bit IEEE-754 floating point number (equivalent to Java's float primitive type) is a subtype of scala.AnyVal.

Float, a 32-bit IEEE-754 floating point number (equivalent to Java's float primitive type) is a subtype of scala.AnyVal. Instances of Float are not represented by an object in the underlying runtime system.

There is an implicit conversion from scala.Float => scala.runtime.RichFloat which provides useful non-primitive operations.

Attributes

Companion
object
Source
Float.scala
Supertypes
class AnyVal
trait Matchable
class Any
object Float

Attributes

Companion
class
Source
Float.scala
Supertypes
class Object
trait Matchable
class Any
Self type
Float.type
object Function

A module defining utility methods for higher-order functional programming.

A module defining utility methods for higher-order functional programming.

Attributes

Source
Function.scala
Supertypes
class Object
trait Matchable
class Any
Self type
Function.type
trait Function0[+R] extends AnyRef

A function of 0 parameters.

A function of 0 parameters.

In the following example, the definition of greeting is shorthand, conceptually, for the anonymous class definition anonfun0, although the implementation details of how the function value is constructed may differ:

object Main extends App {
  val name = "world"
  val greeting = () => s"hello, $name"

  val anonfun0 = new Function0[String] {
    def apply(): String = s"hello, $name"
  }
  assert(greeting() == anonfun0())
}

Attributes

Source
Function0.scala
Supertypes
class Object
trait Matchable
class Any
Known subtypes
Self type
() => R
object Function1

Attributes

Companion
trait
Source
Function1.scala
Supertypes
class Object
trait Matchable
class Any
Self type
Function1.type
trait Function1[-T1, +R] extends AnyRef

A function of 1 parameter.

A function of 1 parameter.

In the following example, the definition of succ is shorthand, conceptually, for the anonymous class definition anonfun1, although the implementation details of how the function value is constructed may differ:

object Main extends App {
  val succ = (x: Int) => x + 1
  val anonfun1 = new Function1[Int, Int] {
    def apply(x: Int): Int = x + 1
  }
  assert(succ(0) == anonfun1(0))
}

Note that the difference between Function1 and scala.PartialFunction is that the latter can specify inputs which it will not handle.

Attributes

Companion
object
Source
Function1.scala
Supertypes
class Object
trait Matchable
class Any
Known subtypes
trait SetOps[A, CC, C]
trait SetOps[A, CC, C]
trait Set[A]
class AbstractSet[A]
class BitSet
class BitSet1
class BitSet2
class BitSetN
class HashSet[A]
class ListSet[A]
class Set1[A]
class Set2[A]
class Set3[A]
class Set4[A]
class TreeSet[A]
class ValueSet
trait SortedSet[A]
trait SortedSetOps[A, CC, C]
trait StrictOptimizedSortedSetOps[A, CC, C]
trait StrictOptimizedSetOps[A, CC, C]
trait SetOps[A, CC, C]
class HashSet[A]
class LinkedHashSet[A]
trait Set[A]
class AbstractSet[A]
class BitSet
class TreeSet[A]
trait SortedSet[A]
trait SortedSetOps[A, CC, C]
trait Set[A]
class AbstractSet[A]
trait SortedSet[A]
trait BitSet
trait SortedSetOps[A, CC, C]
trait BitSetOps[C]
trait SortedSetFactoryDefaults[A, CC, WithFilterCC]
trait StrictOptimizedSortedSetOps[A, CC, C]
trait StrictOptimizedSetOps[A, CC, C]
class FromJavaConsumer[T]
class FromJavaFunction[T, R]
class AbstractFunction1[T1, R]
class From <:< To
class From =:= To
class Conversion[T, U]
trait PartialFunction[A, B]
trait MapOps[K, V, CC, C]
trait MapOps[K, V, CC, C]
trait Map[K, V]
class AbstractMap[K, V]
class HashMap[K, V]
class IntMap[T]
class ListMap[K, V]
class LongMap[T]
class Map1[K, V]
class Map2[K, V]
class Map3[K, V]
class Map4[K, V]
class WithDefault[K, V]
class WithDefault[K, V]
class TreeMap[K, V]
class TreeSeqMap[K, V]
class VectorMap[K, V]
trait SeqMap[K, V]
trait SortedMap[K, V]
trait SortedMapOps[K, V, CC, C]
trait StrictOptimizedSortedMapOps[K, V, CC, C]
trait StrictOptimizedMapOps[K, V, CC, C]
trait MapOps[K, V, CC, C]
class TrieMap[K, V]
class AnyRefMap[K, V]
class CollisionProofHashMap[K, V]
class HashMap[K, V]
class LinkedHashMap[K, V]
class ListMap[K, V]
class LongMap[V]
trait Map[K, V]
trait Map[K, V]
class AbstractMap[K, V]
class WithDefault[K, V]
class WithDefault[K, V]
class OpenHashMap[Key, Value]
class TreeMap[K, V]
trait MultiMap[K, V]
trait SeqMap[K, V]
trait SortedMap[K, V]
trait SortedMapOps[K, V, CC, C]
trait Map[K, V]
class AbstractMap[K, V]
trait DefaultMap[K, V]
trait SeqMap[K, V]
trait SortedMap[K, V]
trait MapFactoryDefaults[K, V, CC, WithFilterCC]
class WeakHashMap[K, V]
trait MapView[K, V]
class AbstractMapView[K, V]
class Filter[K, V]
class FilterKeys[K, V]
class Id[K, V]
class MapValues[K, V, W]
class TapEach[K, V, U]
trait SortedMapFactoryDefaults[K, V, CC, WithFilterCC, UnsortedCC]
trait SortedMapOps[K, V, CC, C]
trait StrictOptimizedSortedMapOps[K, V, CC, C]
trait StrictOptimizedMapOps[K, V, CC, C]
trait Seq[A]
trait Seq[A]
class AbstractSeq[A]
class ArraySeq[A]
class ofBoolean
class ofByte
class ofChar
class ofDouble
class ofFloat
class ofInt
class ofLong
class ofRef[T]
class ofShort
class ofUnit
class LazyList[A]
class List[A]
class ::[A]
object Nil.type
class NumericRange[T]
class Exclusive[T]
class Inclusive[T]
class Queue[A]
class Range
class Exclusive
class Inclusive
class Stream[A]
class Cons[A]
object Empty.type
class Vector[A]
trait IndexedSeq[A]
trait LinearSeq[A]
trait Seq[A]
class AbstractSeq[A]
class AbstractBuffer[A]
class ArrayBuffer[A]
class ArrayDeque[A]
class Queue[A]
class Stack[A]
class ListBuffer[A]
class UnrolledBuffer[T]
class ArraySeq[T]
class ofBoolean
class ofByte
class ofChar
class ofDouble
class ofFloat
class ofInt
class ofLong
class ofRef[T]
class ofShort
class ofUnit
trait Buffer[A]
trait IndexedBuffer[A]
trait IndexedSeq[T]
class Accumulator[A, CC, C]
class AnyAccumulator[A]
class AbstractSeq[A]
trait IndexedSeq[A]
trait LinearSeq[A]
Show all
Self type
T1 => R
trait Function10[-T1, -T2, -T3, -T4, -T5, -T6, -T7, -T8, -T9, -T10, +R] extends AnyRef

A function of 10 parameters.

A function of 10 parameters.

Attributes

Source
Function10.scala
Supertypes
class Object
trait Matchable
class Any
Known subtypes
class AbstractFunction10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, R]
Self type
(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10) => R
trait Function11[-T1, -T2, -T3, -T4, -T5, -T6, -T7, -T8, -T9, -T10, -T11, +R] extends AnyRef

A function of 11 parameters.

A function of 11 parameters.

Attributes

Source
Function11.scala
Supertypes
class Object
trait Matchable
class Any
Known subtypes
class AbstractFunction11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, R]
Self type
(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11) => R
trait Function12[-T1, -T2, -T3, -T4, -T5, -T6, -T7, -T8, -T9, -T10, -T11, -T12, +R] extends AnyRef

A function of 12 parameters.

A function of 12 parameters.

Attributes

Source
Function12.scala
Supertypes
class Object
trait Matchable
class Any
Known subtypes
class AbstractFunction12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, R]
Self type
(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12) => R
trait Function13[-T1, -T2, -T3, -T4, -T5, -T6, -T7, -T8, -T9, -T10, -T11, -T12, -T13, +R] extends AnyRef

A function of 13 parameters.

A function of 13 parameters.

Attributes

Source
Function13.scala
Supertypes
class Object
trait Matchable
class Any
Known subtypes
class AbstractFunction13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, R]
Self type
(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13) => R
trait Function14[-T1, -T2, -T3, -T4, -T5, -T6, -T7, -T8, -T9, -T10, -T11, -T12, -T13, -T14, +R] extends AnyRef

A function of 14 parameters.

A function of 14 parameters.

Attributes

Source
Function14.scala
Supertypes
class Object
trait Matchable
class Any
Known subtypes
class AbstractFunction14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, R]
Self type
(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14) => R
trait Function15[-T1, -T2, -T3, -T4, -T5, -T6, -T7, -T8, -T9, -T10, -T11, -T12, -T13, -T14, -T15, +R] extends AnyRef

A function of 15 parameters.

A function of 15 parameters.

Attributes

Source
Function15.scala
Supertypes
class Object
trait Matchable
class Any
Known subtypes
class AbstractFunction15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, R]
Self type
(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15) => R
trait Function16[-T1, -T2, -T3, -T4, -T5, -T6, -T7, -T8, -T9, -T10, -T11, -T12, -T13, -T14, -T15, -T16, +R] extends AnyRef

A function of 16 parameters.

A function of 16 parameters.

Attributes

Source
Function16.scala
Supertypes
class Object
trait Matchable
class Any
Known subtypes
class AbstractFunction16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, R]
Self type
(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16) => R
trait Function17[-T1, -T2, -T3, -T4, -T5, -T6, -T7, -T8, -T9, -T10, -T11, -T12, -T13, -T14, -T15, -T16, -T17, +R] extends AnyRef

A function of 17 parameters.

A function of 17 parameters.

Attributes

Source
Function17.scala
Supertypes
class Object
trait Matchable
class Any
Known subtypes
class AbstractFunction17[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, R]
Self type
(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17) => R
trait Function18[-T1, -T2, -T3, -T4, -T5, -T6, -T7, -T8, -T9, -T10, -T11, -T12, -T13, -T14, -T15, -T16, -T17, -T18, +R] extends AnyRef

A function of 18 parameters.

A function of 18 parameters.

Attributes

Source
Function18.scala
Supertypes
class Object
trait Matchable
class Any
Known subtypes
class AbstractFunction18[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, R]
Self type
(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18) => R
trait Function19[-T1, -T2, -T3, -T4, -T5, -T6, -T7, -T8, -T9, -T10, -T11, -T12, -T13, -T14, -T15, -T16, -T17, -T18, -T19, +R] extends AnyRef

A function of 19 parameters.

A function of 19 parameters.

Attributes

Source
Function19.scala
Supertypes
class Object
trait Matchable
class Any
Known subtypes
class AbstractFunction19[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, R]
Self type
(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19) => R
trait Function2[-T1, -T2, +R] extends AnyRef

A function of 2 parameters.

A function of 2 parameters.

In the following example, the definition of max is shorthand, conceptually, for the anonymous class definition anonfun2, although the implementation details of how the function value is constructed may differ:

object Main extends App {
  val max = (x: Int, y: Int) => if (x < y) y else x

  val anonfun2 = new Function2[Int, Int, Int] {
    def apply(x: Int, y: Int): Int = if (x < y) y else x
  }
  assert(max(0, 1) == anonfun2(0, 1))
}

Attributes

Source
Function2.scala
Supertypes
class Object
trait Matchable
class Any
Known subtypes
class FromJavaBiConsumer[T, U]
class FromJavaBiFunction[T, U, R]
class FromJavaBiPredicate[T, U]
class AbstractFunction2[T1, T2, R]
Show all
Self type
(T1, T2) => R
trait Function20[-T1, -T2, -T3, -T4, -T5, -T6, -T7, -T8, -T9, -T10, -T11, -T12, -T13, -T14, -T15, -T16, -T17, -T18, -T19, -T20, +R] extends AnyRef

A function of 20 parameters.

A function of 20 parameters.

Attributes

Source
Function20.scala
Supertypes
class Object
trait Matchable
class Any
Known subtypes
class AbstractFunction20[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, R]
Self type
(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20) => R
trait Function21[-T1, -T2, -T3, -T4, -T5, -T6, -T7, -T8, -T9, -T10, -T11, -T12, -T13, -T14, -T15, -T16, -T17, -T18, -T19, -T20, -T21, +R] extends AnyRef

A function of 21 parameters.

A function of 21 parameters.

Attributes

Source
Function21.scala
Supertypes
class Object
trait Matchable
class Any
Known subtypes
class AbstractFunction21[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, R]
Self type
(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21) => R
trait Function22[-T1, -T2, -T3, -T4, -T5, -T6, -T7, -T8, -T9, -T10, -T11, -T12, -T13, -T14, -T15, -T16, -T17, -T18, -T19, -T20, -T21, -T22, +R] extends AnyRef

A function of 22 parameters.

A function of 22 parameters.

Attributes

Source
Function22.scala
Supertypes
class Object
trait Matchable
class Any
Known subtypes
class AbstractFunction22[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, R]
Self type
(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22) => R
trait Function3[-T1, -T2, -T3, +R] extends AnyRef

A function of 3 parameters.

A function of 3 parameters.

Attributes

Source
Function3.scala
Supertypes
class Object
trait Matchable
class Any
Known subtypes
class AbstractFunction3[T1, T2, T3, R]
Self type
(T1, T2, T3) => R
trait Function4[-T1, -T2, -T3, -T4, +R] extends AnyRef

A function of 4 parameters.

A function of 4 parameters.

Attributes

Source
Function4.scala
Supertypes
class Object
trait Matchable
class Any
Known subtypes
class AbstractFunction4[T1, T2, T3, T4, R]
Self type
(T1, T2, T3, T4) => R
trait Function5[-T1, -T2, -T3, -T4, -T5, +R] extends AnyRef

A function of 5 parameters.

A function of 5 parameters.

Attributes

Source
Function5.scala
Supertypes
class Object
trait Matchable
class Any
Known subtypes
class AbstractFunction5[T1, T2, T3, T4, T5, R]
Self type
(T1, T2, T3, T4, T5) => R
trait Function6[-T1, -T2, -T3, -T4, -T5, -T6, +R] extends AnyRef

A function of 6 parameters.

A function of 6 parameters.

Attributes

Source
Function6.scala
Supertypes
class Object
trait Matchable
class Any
Known subtypes
class AbstractFunction6[T1, T2, T3, T4, T5, T6, R]
Self type
(T1, T2, T3, T4, T5, T6) => R
trait Function7[-T1, -T2, -T3, -T4, -T5, -T6, -T7, +R] extends AnyRef

A function of 7 parameters.

A function of 7 parameters.

Attributes

Source
Function7.scala
Supertypes
class Object
trait Matchable
class Any
Known subtypes
class AbstractFunction7[T1, T2, T3, T4, T5, T6, T7, R]
Self type
(T1, T2, T3, T4, T5, T6, T7) => R
trait Function8[-T1, -T2, -T3, -T4, -T5, -T6, -T7, -T8, +R] extends AnyRef

A function of 8 parameters.

A function of 8 parameters.

Attributes

Source
Function8.scala
Supertypes
class Object
trait Matchable
class Any
Known subtypes
class AbstractFunction8[T1, T2, T3, T4, T5, T6, T7, T8, R]
Self type
(T1, T2, T3, T4, T5, T6, T7, T8) => R
trait Function9[-T1, -T2, -T3, -T4, -T5, -T6, -T7, -T8, -T9, +R] extends AnyRef

A function of 9 parameters.

A function of 9 parameters.

Attributes

Source
Function9.scala
Supertypes
class Object
trait Matchable
class Any
Known subtypes
class AbstractFunction9[T1, T2, T3, T4, T5, T6, T7, T8, T9, R]
Self type
(T1, T2, T3, T4, T5, T6, T7, T8, T9) => R
object IArray

An immutable array. An IArray[T] has the same representation as an Array[T], but it cannot be updated. Unlike regular arrays, immutable arrays are covariant.

An immutable array. An IArray[T] has the same representation as an Array[T], but it cannot be updated. Unlike regular arrays, immutable arrays are covariant.

Attributes

Source
IArray.scala
Supertypes
class Object
trait Matchable
class Any
Self type
IArray.type
final abstract class Int extends AnyVal

Int, a 32-bit signed integer (equivalent to Java's int primitive type) is a subtype of scala.AnyVal.

Int, a 32-bit signed integer (equivalent to Java's int primitive type) is a subtype of scala.AnyVal. Instances of Int are not represented by an object in the underlying runtime system.

There is an implicit conversion from scala.Int => scala.runtime.RichInt which provides useful non-primitive operations.

Attributes

Companion
object
Source
Int.scala
Supertypes
class AnyVal
trait Matchable
class Any
object Int

Attributes

Companion
class
Source
Int.scala
Supertypes
class Object
trait Matchable
class Any
Self type
Int.type
final abstract class Long extends AnyVal

Long, a 64-bit signed integer (equivalent to Java's long primitive type) is a subtype of scala.AnyVal.

Long, a 64-bit signed integer (equivalent to Java's long primitive type) is a subtype of scala.AnyVal. Instances of Long are not represented by an object in the underlying runtime system.

There is an implicit conversion from scala.Long => scala.runtime.RichLong which provides useful non-primitive operations.

Attributes

Companion
object
Source
Long.scala
Supertypes
class AnyVal
trait Matchable
class Any
object Long

Attributes

Companion
class
Source
Long.scala
Supertypes
class Object
trait Matchable
class Any
Self type
Long.type
final class MatchError(obj: Any) extends RuntimeException

This class implements errors which are thrown whenever an object doesn't match any pattern of a pattern matching expression.

This class implements errors which are thrown whenever an object doesn't match any pattern of a pattern matching expression.

Attributes

Source
MatchError.scala
Supertypes
class Exception
class Throwable
trait Serializable
class Object
trait Matchable
class Any
Show all
open class Matchable

The base trait of types that can be safely pattern matched against.

The base trait of types that can be safely pattern matched against.

See https://docs.scala-lang.org/scala3/reference/other-new-features/matchable.html.

Attributes

Supertypes
class Any
sealed trait NonEmptyTuple extends Tuple

Tuple of arbitrary non-zero arity

Tuple of arbitrary non-zero arity

Attributes

Source
Tuple.scala
Supertypes
trait Tuple
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
Known subtypes
class H *: T
case object None extends Option[Nothing]

This case object represents non-existent values.

This case object represents non-existent values.

Attributes

Source
Option.scala
Supertypes
trait Singleton
trait Product
trait Mirror
class Option[Nothing]
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
Self type
None.type
final class NotImplementedError(msg: String) extends Error

Throwing this exception can be a temporary replacement for a method body that remains to be implemented.

Throwing this exception can be a temporary replacement for a method body that remains to be implemented. For instance, the exception is thrown by Predef.???.

Attributes

Source
NotImplementedError.scala
Supertypes
class Error
class Throwable
trait Serializable
class Object
trait Matchable
class Any
Show all
final abstract open class Nothing

Nothing is - together with scala.Null - at the bottom of Scala's type hierarchy.

Nothing is - together with scala.Null - at the bottom of Scala's type hierarchy.

Nothing is a subtype of every other type (including scala.Null); there exist no instances of this type. Although type Nothing is uninhabited, it is nevertheless useful in several ways. For instance, the Scala library defines a value scala.collection.immutable.Nil of type List[Nothing]. Because lists are covariant in Scala, this makes scala.collection.immutable.Nil an instance of List[T], for any element of type T.

Another usage for Nothing is the return type for methods which never return normally. One example is method error in scala.sys, which always throws an exception.

Attributes

Supertypes
class Any
final abstract open class Null

Null is - together with scala.Nothing - at the bottom of the Scala type hierarchy.

Null is - together with scala.Nothing - at the bottom of the Scala type hierarchy.

Null is the type of the null literal. It is a subtype of every type except those of value classes. Value classes are subclasses of AnyVal, which includes primitive types such as Int, Boolean, and user-defined value classes.

Since Null is not a subtype of value types, null is not a member of any such type. For instance, it is not possible to assign null to a variable of type scala.Int.

Attributes

Supertypes
class Object
trait Matchable
class Any
object Option

Attributes

Companion
class
Source
Option.scala
Supertypes
trait Sum
trait Mirror
class Object
trait Matchable
class Any
Self type
Option.type
sealed abstract class Option[+A] extends IterableOnce[A], Product, Serializable

Represents optional values.

Represents optional values. Instances of Option are either an instance of $some or the object $none.

The most idiomatic way to use an $option instance is to treat it as a collection or monad and use map,flatMap, filter, or foreach:

val name: Option[String] = request getParameter "name"
val upper = name map { _.trim } filter { _.length != 0 } map { _.toUpperCase }
println(upper getOrElse "")

Note that this is equivalent to

val upper = for {
  name <- request getParameter "name"
  trimmed <- Some(name.trim)
  upper <- Some(trimmed.toUpperCase) if trimmed.length != 0
} yield upper
println(upper getOrElse "")

Because of how for comprehension works, if $none is returned from request.getParameter, the entire expression results in $none

This allows for sophisticated chaining of $option values without having to check for the existence of a value.

These are useful methods that exist for both $some and $none. - isDefined — True if not empty - isEmpty — True if empty - nonEmpty — True if not empty - orElse — Evaluate and return alternate optional value if empty - getOrElse — Evaluate and return alternate value if empty - get — Return value, throw exception if empty - fold — Apply function on optional value, return default if empty - map — Apply a function on the optional value - flatMap — Same as map but function must return an optional value - foreach — Apply a procedure on option value - collect — Apply partial pattern match on optional value - filter — An optional value satisfies predicate - filterNot — An optional value doesn't satisfy predicate - exists — Apply predicate on optional value, or false if empty - forall — Apply predicate on optional value, or true if empty - contains — Checks if value equals optional value, or false if empty - zip — Combine two optional values to make a paired optional value - unzip — Split an optional pair to two optional values - unzip3 — Split an optional triple to three optional values - toList — Unary list of optional value, otherwise the empty list

A less-idiomatic way to use $option values is via pattern matching:

val nameMaybe = request getParameter "name"
nameMaybe match {
  case Some(name) =>
    println(name.trim.toUppercase)
  case None =>
    println("No name value")
}

Interacting with code that can occasionally return null can be safely wrapped in $option to become $none and $some otherwise.

val abc = new java.util.HashMap[Int, String]
abc.put(1, "A")
bMaybe = Option(abc.get(2))
bMaybe match {
 case Some(b) =>
   println(s"Found $b")
 case None =>
   println("Not found")
}

Attributes

Note

Many of the methods in here are duplicative with those in the Iterable hierarchy, but they are duplicated for a reason: the implicit conversion tends to leave one with an Iterable in situations where one could have retained an Option.

Companion
object
Source
Option.scala
Supertypes
trait Serializable
trait Product
trait Equals
trait IterableOnce[A]
class Object
trait Matchable
class Any
Show all
Known subtypes
object None.type
class Some[A]
Self type
Option[A]
trait PartialFunction[-A, +B] extends A => B

A partial function of type PartialFunction[A, B] is a unary function where the domain does not necessarily include all values of type A.

A partial function of type PartialFunction[A, B] is a unary function where the domain does not necessarily include all values of type A. The function isDefinedAt allows to test dynamically if a value is in the domain of the function.

Even if isDefinedAt returns true for an a: A, calling apply(a) may still throw an exception, so the following code is legal:

val f: PartialFunction[Int, Any] = { case x => x / 0 }   // ArithmeticException: / by zero

It is the responsibility of the caller to call isDefinedAt before calling apply, because if isDefinedAt is false, it is not guaranteed apply will throw an exception to indicate an error condition. If an exception is not thrown, evaluation may result in an arbitrary value.

The usual way to respect this contract is to call applyOrElse, which is expected to be more efficient than calling both isDefinedAt and apply.

The main distinction between PartialFunction and scala.Function1 is that the user of a PartialFunction may choose to do something different with input that is declared to be outside its domain. For example:

val sample = 1 to 10
def isEven(n: Int) = n % 2 == 0
val eveningNews: PartialFunction[Int, String] = {
  case x if isEven(x) => s"$x is even"
}

// The method collect is described as "filter + map"
// because it uses a PartialFunction to select elements
// to which the function is applied.
val evenNumbers = sample.collect(eveningNews)

val oddlyEnough: PartialFunction[Int, String] = {
  case x if !isEven(x) => s"$x is odd"
}

// The method orElse allows chaining another PartialFunction
// to handle input outside the declared domain.
val numbers = sample.map(eveningNews orElse oddlyEnough)

// same as
val numbers = sample.map(n => eveningNews.applyOrElse(n, oddlyEnough))

val half: PartialFunction[Int, Int] = {
  case x if isEven(x) => x / 2
}

// Calculating the domain of a composition can be expensive.
val oddByHalf = half.andThen(oddlyEnough)

// Invokes `half.apply` on even elements!
val oddBalls = sample.filter(oddByHalf.isDefinedAt)

// Better than filter(oddByHalf.isDefinedAt).map(oddByHalf)
val oddBalls = sample.collect(oddByHalf)

// Providing "default" values.
val oddsAndEnds = sample.map(n => oddByHalf.applyOrElse(n, (i: Int) => s"[$i]"))

Attributes

Note

Optional Functions, PartialFunctions and extractor objects can be converted to each other as shown in the following table.  

How to convert ...

to a PartialFunction

to an optional Function

to an extractor

from a PartialFunction

Predef.identity

lift

Predef.identity

from optional Function

Function1.UnliftOps#unlift or Function.unlift

Predef.identity

Function1.UnliftOps#unlift

from an extractor

{ case extractor(x) => x }

extractor.unapply _

Predef.identity

 

Companion
object
Source
PartialFunction.scala
Supertypes
trait A => B
class Object
trait Matchable
class Any
Known subtypes
trait MapOps[K, V, CC, C]
trait MapOps[K, V, CC, C]
trait Map[K, V]
class AbstractMap[K, V]
class HashMap[K, V]
class IntMap[T]
class ListMap[K, V]
class LongMap[T]
class Map1[K, V]
class Map2[K, V]
class Map3[K, V]
class Map4[K, V]
class WithDefault[K, V]
class WithDefault[K, V]
class TreeMap[K, V]
class TreeSeqMap[K, V]
class VectorMap[K, V]
trait SeqMap[K, V]
trait SortedMap[K, V]
trait SortedMapOps[K, V, CC, C]
trait StrictOptimizedSortedMapOps[K, V, CC, C]
trait StrictOptimizedMapOps[K, V, CC, C]
trait MapOps[K, V, CC, C]
class TrieMap[K, V]
class AnyRefMap[K, V]
class CollisionProofHashMap[K, V]
class HashMap[K, V]
class LinkedHashMap[K, V]
class ListMap[K, V]
class LongMap[V]
trait Map[K, V]
trait Map[K, V]
class AbstractMap[K, V]
class WithDefault[K, V]
class WithDefault[K, V]
class OpenHashMap[Key, Value]
class TreeMap[K, V]
trait MultiMap[K, V]
trait SeqMap[K, V]
trait SortedMap[K, V]
trait SortedMapOps[K, V, CC, C]
trait Map[K, V]
class AbstractMap[K, V]
trait DefaultMap[K, V]
trait SeqMap[K, V]
trait SortedMap[K, V]
trait MapFactoryDefaults[K, V, CC, WithFilterCC]
class WeakHashMap[K, V]
trait MapView[K, V]
class AbstractMapView[K, V]
class Filter[K, V]
class FilterKeys[K, V]
class Id[K, V]
class MapValues[K, V, W]
class TapEach[K, V, U]
trait SortedMapFactoryDefaults[K, V, CC, WithFilterCC, UnsortedCC]
trait SortedMapOps[K, V, CC, C]
trait StrictOptimizedSortedMapOps[K, V, CC, C]
trait StrictOptimizedMapOps[K, V, CC, C]
trait Seq[A]
trait Seq[A]
class AbstractSeq[A]
class ArraySeq[A]
class ofBoolean
class ofByte
class ofChar
class ofDouble
class ofFloat
class ofInt
class ofLong
class ofRef[T]
class ofShort
class ofUnit
class LazyList[A]
class List[A]
class ::[A]
object Nil.type
class NumericRange[T]
class Exclusive[T]
class Inclusive[T]
class Queue[A]
class Range
class Exclusive
class Inclusive
class Stream[A]
class Cons[A]
object Empty.type
class Vector[A]
trait IndexedSeq[A]
trait LinearSeq[A]
trait Seq[A]
class AbstractSeq[A]
class AbstractBuffer[A]
class ArrayBuffer[A]
class ArrayDeque[A]
class Queue[A]
class Stack[A]
class ListBuffer[A]
class UnrolledBuffer[T]
class ArraySeq[T]
class ofBoolean
class ofByte
class ofChar
class ofDouble
class ofFloat
class ofInt
class ofLong
class ofRef[T]
class ofShort
class ofUnit
trait Buffer[A]
trait IndexedBuffer[A]
trait IndexedSeq[T]
class Accumulator[A, CC, C]
class AnyAccumulator[A]
class AbstractSeq[A]
trait IndexedSeq[A]
trait LinearSeq[A]
Show all
Self type

A few handy operations which leverage the extra bit of information available in partial functions.

A few handy operations which leverage the extra bit of information available in partial functions. Examples:

import PartialFunction._

def strangeConditional(other: Any): Boolean = cond(other) {
  case x: String if x == "abc" || x == "def"  => true
  case x: Int => true
}
def onlyInt(v: Any): Option[Int] = condOpt(v) { case x: Int => x }

Attributes

Companion
trait
Source
PartialFunction.scala
Supertypes
class Object
trait Matchable
class Any
Self type
trait PolyFunction

Marker trait for polymorphic function types.

Marker trait for polymorphic function types.

This is the only trait that can be refined with a polymorphic method, as long as that method is called apply, e.g.: PolyFunction { def apply[T_1, ..., T_M](x_1: P_1, ..., x_N: P_N): R } This type will be erased to FunctionN.

Attributes

Source
PolyFunction.scala
Supertypes
class Object
trait Matchable
class Any
object Predef

The Predef object provides definitions that are accessible in all Scala compilation units without explicit qualification.

The Predef object provides definitions that are accessible in all Scala compilation units without explicit qualification.

Commonly Used Types

Predef provides type aliases for types which are commonly used, such as the immutable collection types scala.collection.immutable.Map and scala.collection.immutable.Set.

Console Output

For basic console output, Predef provides convenience methods print and println, which are aliases of the methods in the object scala.Console.

Assertions

A set of assert functions are provided for use as a way to document and dynamically check invariants in code. Invocations of assert can be elided at compile time by providing the command line option -Xdisable-assertions, which raises -Xelide-below above elidable.ASSERTION, to the scalac command.

Variants of assert intended for use with static analysis tools are also provided: assume, require and ensuring. require and ensuring are intended for use as a means of design-by-contract style specification of pre- and post-conditions on functions, with the intention that these specifications could be consumed by a static analysis tool. For instance,

def addNaturals(nats: List[Int]): Int = {
  require(nats forall (_ >= 0), "List contains negative numbers")
  nats.foldLeft(0)(_ + _)
} ensuring(_ >= 0)

The declaration of addNaturals states that the list of integers passed should only contain natural numbers (i.e. non-negative), and that the result returned will also be natural. require is distinct from assert in that if the condition fails, then the caller of the function is to blame rather than a logical error having been made within addNaturals itself. ensuring is a form of assert that declares the guarantee the function is providing with regards to its return value.

Implicit Conversions

A number of commonly applied implicit conversions are also defined here, and in the parent type scala.LowPriorityImplicits. Implicit conversions are provided for the "widening" of numeric values, for instance, converting a Short value to a Long value as required, and to add additional higher-order functions to Array values. These are described in more detail in the documentation of scala.Array.

Attributes

Source
Predef.scala
Supertypes
class Object
trait Matchable
class Any
Self type
Predef.type
trait Product extends Equals

Base trait for all products, which in the standard library include at least scala.Product1 through scala.Product22 and therefore also their subclasses scala.Tuple1 through scala.Tuple22.

Base trait for all products, which in the standard library include at least scala.Product1 through scala.Product22 and therefore also their subclasses scala.Tuple1 through scala.Tuple22. In addition, all case classes implement Product with synthetically generated methods.

Attributes

Source
Product.scala
Supertypes
trait Equals
class Any
Known subtypes
trait Enum
trait EnumValue
class TupleXXL
class Either[A, B]
class Left[A, B]
class Right[A, B]
class Try[T]
class Failure[T]
class Success[T]
class Option[A]
object None.type
class Some[A]
trait Product1[T1]
class (T1)
trait Product10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]
class (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10)
trait Product11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11]
class (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11)
trait Product12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12]
class (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12)
trait Product13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13]
class (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13)
trait Product14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14]
class (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14)
trait Product15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15]
class (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15)
trait Product16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16]
class (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16)
trait Product17[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17]
class (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17)
trait Product18[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18]
class (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18)
trait Product19[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19]
class (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19)
trait Product2[T1, T2]
class (T1, T2)
trait Product20[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20]
class (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20)
trait Product21[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21]
class (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21)
trait Product22[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22]
class (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22)
trait Product3[T1, T2, T3]
class (T1, T2, T3)
trait Product4[T1, T2, T3, T4]
class (T1, T2, T3, T4)
trait Product5[T1, T2, T3, T4, T5]
class (T1, T2, T3, T4, T5)
trait Product6[T1, T2, T3, T4, T5, T6]
class (T1, T2, T3, T4, T5, T6)
trait Product7[T1, T2, T3, T4, T5, T6, T7]
class (T1, T2, T3, T4, T5, T6, T7)
trait Product8[T1, T2, T3, T4, T5, T6, T7, T8]
class (T1, T2, T3, T4, T5, T6, T7, T8)
trait Product9[T1, T2, T3, T4, T5, T6, T7, T8, T9]
class (T1, T2, T3, T4, T5, T6, T7, T8, T9)
trait Tuple
object EmptyTuple.type
class H *: T
Show all
object Product1

Attributes

Companion
trait
Source
Product1.scala
Supertypes
class Object
trait Matchable
class Any
Self type
Product1.type
trait Product1[+T1] extends Product

Product1 is a Cartesian product of 1 component.

Product1 is a Cartesian product of 1 component.

Attributes

Companion
object
Source
Product1.scala
Supertypes
trait Product
trait Equals
class Any
Known subtypes
class (T1)
object Product10

Attributes

Companion
trait
Source
Product10.scala
Supertypes
class Object
trait Matchable
class Any
Self type
Product10.type
trait Product10[+T1, +T2, +T3, +T4, +T5, +T6, +T7, +T8, +T9, +T10] extends Product

Product10 is a Cartesian product of 10 components.

Product10 is a Cartesian product of 10 components.

Attributes

Companion
object
Source
Product10.scala
Supertypes
trait Product
trait Equals
class Any
Known subtypes
class (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10)
object Product11

Attributes

Companion
trait
Source
Product11.scala
Supertypes
class Object
trait Matchable
class Any
Self type
Product11.type
trait Product11[+T1, +T2, +T3, +T4, +T5, +T6, +T7, +T8, +T9, +T10, +T11] extends Product

Product11 is a Cartesian product of 11 components.

Product11 is a Cartesian product of 11 components.

Attributes

Companion
object
Source
Product11.scala
Supertypes
trait Product
trait Equals
class Any
Known subtypes
class (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11)
object Product12

Attributes

Companion
trait
Source
Product12.scala
Supertypes
class Object
trait Matchable
class Any
Self type
Product12.type
trait Product12[+T1, +T2, +T3, +T4, +T5, +T6, +T7, +T8, +T9, +T10, +T11, +T12] extends Product

Product12 is a Cartesian product of 12 components.

Product12 is a Cartesian product of 12 components.

Attributes

Companion
object
Source
Product12.scala
Supertypes
trait Product
trait Equals
class Any
Known subtypes
class (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12)
object Product13

Attributes

Companion
trait
Source
Product13.scala
Supertypes
class Object
trait Matchable
class Any
Self type
Product13.type
trait Product13[+T1, +T2, +T3, +T4, +T5, +T6, +T7, +T8, +T9, +T10, +T11, +T12, +T13] extends Product

Product13 is a Cartesian product of 13 components.

Product13 is a Cartesian product of 13 components.

Attributes

Companion
object
Source
Product13.scala
Supertypes
trait Product
trait Equals
class Any
Known subtypes
class (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13)
object Product14

Attributes

Companion
trait
Source
Product14.scala
Supertypes
class Object
trait Matchable
class Any
Self type
Product14.type
trait Product14[+T1, +T2, +T3, +T4, +T5, +T6, +T7, +T8, +T9, +T10, +T11, +T12, +T13, +T14] extends Product

Product14 is a Cartesian product of 14 components.

Product14 is a Cartesian product of 14 components.

Attributes

Companion
object
Source
Product14.scala
Supertypes
trait Product
trait Equals
class Any
Known subtypes
class (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14)
object Product15

Attributes

Companion
trait
Source
Product15.scala
Supertypes
class Object
trait Matchable
class Any
Self type
Product15.type
trait Product15[+T1, +T2, +T3, +T4, +T5, +T6, +T7, +T8, +T9, +T10, +T11, +T12, +T13, +T14, +T15] extends Product

Product15 is a Cartesian product of 15 components.

Product15 is a Cartesian product of 15 components.

Attributes

Companion
object
Source
Product15.scala
Supertypes
trait Product
trait Equals
class Any
Known subtypes
class (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15)
object Product16

Attributes

Companion
trait
Source
Product16.scala
Supertypes
class Object
trait Matchable
class Any
Self type
Product16.type
trait Product16[+T1, +T2, +T3, +T4, +T5, +T6, +T7, +T8, +T9, +T10, +T11, +T12, +T13, +T14, +T15, +T16] extends Product

Product16 is a Cartesian product of 16 components.

Product16 is a Cartesian product of 16 components.

Attributes

Companion
object
Source
Product16.scala
Supertypes
trait Product
trait Equals
class Any
Known subtypes
class (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16)
object Product17

Attributes

Companion
trait
Source
Product17.scala
Supertypes
class Object
trait Matchable
class Any
Self type
Product17.type
trait Product17[+T1, +T2, +T3, +T4, +T5, +T6, +T7, +T8, +T9, +T10, +T11, +T12, +T13, +T14, +T15, +T16, +T17] extends Product

Product17 is a Cartesian product of 17 components.

Product17 is a Cartesian product of 17 components.

Attributes

Companion
object
Source
Product17.scala
Supertypes
trait Product
trait Equals
class Any
Known subtypes
class (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17)
object Product18

Attributes

Companion
trait
Source
Product18.scala
Supertypes
class Object
trait Matchable
class Any
Self type
Product18.type
trait Product18[+T1, +T2, +T3, +T4, +T5, +T6, +T7, +T8, +T9, +T10, +T11, +T12, +T13, +T14, +T15, +T16, +T17, +T18] extends Product

Product18 is a Cartesian product of 18 components.

Product18 is a Cartesian product of 18 components.

Attributes

Companion
object
Source
Product18.scala
Supertypes
trait Product
trait Equals
class Any
Known subtypes
class (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18)
object Product19

Attributes

Companion
trait
Source
Product19.scala
Supertypes
class Object
trait Matchable
class Any
Self type
Product19.type
trait Product19[+T1, +T2, +T3, +T4, +T5, +T6, +T7, +T8, +T9, +T10, +T11, +T12, +T13, +T14, +T15, +T16, +T17, +T18, +T19] extends Product

Product19 is a Cartesian product of 19 components.

Product19 is a Cartesian product of 19 components.

Attributes

Companion
object
Source
Product19.scala
Supertypes
trait Product
trait Equals
class Any
Known subtypes
class (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19)
object Product2

Attributes

Companion
trait
Source
Product2.scala
Supertypes
class Object
trait Matchable
class Any
Self type
Product2.type
trait Product2[+T1, +T2] extends Product

Product2 is a Cartesian product of 2 components.

Product2 is a Cartesian product of 2 components.

Attributes

Companion
object
Source
Product2.scala
Supertypes
trait Product
trait Equals
class Any
Known subtypes
class (T1, T2)
object Product20

Attributes

Companion
trait
Source
Product20.scala
Supertypes
class Object
trait Matchable
class Any
Self type
Product20.type
trait Product20[+T1, +T2, +T3, +T4, +T5, +T6, +T7, +T8, +T9, +T10, +T11, +T12, +T13, +T14, +T15, +T16, +T17, +T18, +T19, +T20] extends Product

Product20 is a Cartesian product of 20 components.

Product20 is a Cartesian product of 20 components.

Attributes

Companion
object
Source
Product20.scala
Supertypes
trait Product
trait Equals
class Any
Known subtypes
class (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20)
object Product21

Attributes

Companion
trait
Source
Product21.scala
Supertypes
class Object
trait Matchable
class Any
Self type
Product21.type
trait Product21[+T1, +T2, +T3, +T4, +T5, +T6, +T7, +T8, +T9, +T10, +T11, +T12, +T13, +T14, +T15, +T16, +T17, +T18, +T19, +T20, +T21] extends Product

Product21 is a Cartesian product of 21 components.

Product21 is a Cartesian product of 21 components.

Attributes

Companion
object
Source
Product21.scala
Supertypes
trait Product
trait Equals
class Any
Known subtypes
class (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21)
object Product22

Attributes

Companion
trait
Source
Product22.scala
Supertypes
class Object
trait Matchable
class Any
Self type
Product22.type
trait Product22[+T1, +T2, +T3, +T4, +T5, +T6, +T7, +T8, +T9, +T10, +T11, +T12, +T13, +T14, +T15, +T16, +T17, +T18, +T19, +T20, +T21, +T22] extends Product

Product22 is a Cartesian product of 22 components.

Product22 is a Cartesian product of 22 components.

Attributes

Companion
object
Source
Product22.scala
Supertypes
trait Product
trait Equals
class Any
Known subtypes
class (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22)
object Product3

Attributes

Companion
trait
Source
Product3.scala
Supertypes
class Object
trait Matchable
class Any
Self type
Product3.type
trait Product3[+T1, +T2, +T3] extends Product

Product3 is a Cartesian product of 3 components.

Product3 is a Cartesian product of 3 components.

Attributes

Companion
object
Source
Product3.scala
Supertypes
trait Product
trait Equals
class Any
Known subtypes
class (T1, T2, T3)
object Product4

Attributes

Companion
trait
Source
Product4.scala
Supertypes
class Object
trait Matchable
class Any
Self type
Product4.type
trait Product4[+T1, +T2, +T3, +T4] extends Product

Product4 is a Cartesian product of 4 components.

Product4 is a Cartesian product of 4 components.

Attributes

Companion
object
Source
Product4.scala
Supertypes
trait Product
trait Equals
class Any
Known subtypes
class (T1, T2, T3, T4)
object Product5

Attributes

Companion
trait
Source
Product5.scala
Supertypes
class Object
trait Matchable
class Any
Self type
Product5.type
trait Product5[+T1, +T2, +T3, +T4, +T5] extends Product

Product5 is a Cartesian product of 5 components.

Product5 is a Cartesian product of 5 components.

Attributes

Companion
object
Source
Product5.scala
Supertypes
trait Product
trait Equals
class Any
Known subtypes
class (T1, T2, T3, T4, T5)
object Product6

Attributes

Companion
trait
Source
Product6.scala
Supertypes
class Object
trait Matchable
class Any
Self type
Product6.type
trait Product6[+T1, +T2, +T3, +T4, +T5, +T6] extends Product

Product6 is a Cartesian product of 6 components.

Product6 is a Cartesian product of 6 components.

Attributes

Companion
object
Source
Product6.scala
Supertypes
trait Product
trait Equals
class Any
Known subtypes
class (T1, T2, T3, T4, T5, T6)
object Product7

Attributes

Companion
trait
Source
Product7.scala
Supertypes
class Object
trait Matchable
class Any
Self type
Product7.type
trait Product7[+T1, +T2, +T3, +T4, +T5, +T6, +T7] extends Product

Product7 is a Cartesian product of 7 components.

Product7 is a Cartesian product of 7 components.

Attributes

Companion
object
Source
Product7.scala
Supertypes
trait Product
trait Equals
class Any
Known subtypes
class (T1, T2, T3, T4, T5, T6, T7)
object Product8

Attributes

Companion
trait
Source
Product8.scala
Supertypes
class Object
trait Matchable
class Any
Self type
Product8.type
trait Product8[+T1, +T2, +T3, +T4, +T5, +T6, +T7, +T8] extends Product

Product8 is a Cartesian product of 8 components.

Product8 is a Cartesian product of 8 components.

Attributes

Companion
object
Source
Product8.scala
Supertypes
trait Product
trait Equals
class Any
Known subtypes
class (T1, T2, T3, T4, T5, T6, T7, T8)
object Product9

Attributes

Companion
trait
Source
Product9.scala
Supertypes
class Object
trait Matchable
class Any
Self type
Product9.type
trait Product9[+T1, +T2, +T3, +T4, +T5, +T6, +T7, +T8, +T9] extends Product

Product9 is a Cartesian product of 9 components.

Product9 is a Cartesian product of 9 components.

Attributes

Companion
object
Source
Product9.scala
Supertypes
trait Product
trait Equals
class Any
Known subtypes
class (T1, T2, T3, T4, T5, T6, T7, T8, T9)
case class ScalaReflectionException(msg: String) extends Exception

An exception that indicates an error during Scala reflection

An exception that indicates an error during Scala reflection

Attributes

Source
package.scala
Supertypes
trait Product
trait Equals
class Exception
class Throwable
trait Serializable
class Object
trait Matchable
class Any
Show all
trait Selectable

A marker trait for objects that support structural selection via selectDynamic and applyDynamic

A marker trait for objects that support structural selection via selectDynamic and applyDynamic

Implementation classes should define, or make available as extension methods, the following two method signatures:

  def selectDynamic(name: String): Any
  def applyDynamic(name: String)(args: Any*): Any =

selectDynamic is invoked for simple selections v.m, whereas applyDynamic is invoked for selections with arguments v.m(...). If there's only one kind of selection, the method supporting the other may be omitted. The applyDynamic can also have a second parameter list of java.lang.Class arguments, i.e. it may alternatively have the signature

  def applyDynamic(name: String, paramClasses: Class[_]*)(args: Any*): Any

In this case the call will synthesize Class arguments for the erasure of all formal parameter types of the method in the structural type.

Attributes

Companion
object
Source
Selectable.scala
Supertypes
class Any
Known subtypes
object Selectable

Attributes

Companion
trait
Source
Selectable.scala
Supertypes
class Object
trait Matchable
class Any
Self type
Selectable.type
class SerialVersionUID(value: Long) extends ConstantAnnotation

Annotation for specifying the serialVersionUID field of a (serializable) class.

Annotation for specifying the serialVersionUID field of a (serializable) class.

On the JVM, a class with this annotation will receive a private, static, and final field called serialVersionUID with the provided value, which the JVM's serialization mechanism uses to determine serialization compatibility between different versions of a class.

Attributes

See also
Source
SerialVersionUID.scala
Supertypes
class Annotation
class Object
trait Matchable
class Any
Show all
final abstract class Short extends AnyVal

Short, a 16-bit signed integer (equivalent to Java's short primitive type) is a subtype of scala.AnyVal.

Short, a 16-bit signed integer (equivalent to Java's short primitive type) is a subtype of scala.AnyVal. Instances of Short are not represented by an object in the underlying runtime system.

There is an implicit conversion from scala.Short => scala.runtime.RichShort which provides useful non-primitive operations.

Attributes

Companion
object
Source
Short.scala
Supertypes
class AnyVal
trait Matchable
class Any
object Short

Attributes

Companion
class
Source
Short.scala
Supertypes
class Object
trait Matchable
class Any
Self type
Short.type
final open class Singleton

Singleton is used by the compiler as a supertype for singleton types.

Singleton is used by the compiler as a supertype for singleton types. This includes literal types, as they are also singleton types.

scala> object A { val x = 42 }
defined object A

scala> implicitly[A.type <:< Singleton]
res12: A.type <:< Singleton = generalized constraint

scala> implicitly[A.x.type <:< Singleton]
res13: A.x.type <:< Singleton = generalized constraint

scala> implicitly[42 <:< Singleton]
res14: 42 <:< Singleton = generalized constraint

scala> implicitly[Int <:< Singleton]
^
error: Cannot prove that Int <:< Singleton.

Singleton has a special meaning when it appears as an upper bound on a formal type parameter. Normally, type inference in Scala widens singleton types to the underlying non-singleton type. When a type parameter has an explicit upper bound of Singleton, the compiler infers a singleton type.

scala> def check42[T](x: T)(implicit ev: T =:= 42): T = x
check42: [T](x: T)(implicit ev: T =:= 42)T

scala> val x1 = check42(42)
^
error: Cannot prove that Int =:= 42.

scala> def singleCheck42[T <: Singleton](x: T)(implicit ev: T =:= 42): T = x
singleCheck42: [T <: Singleton](x: T)(implicit ev: T =:= 42)T

scala> val x2 = singleCheck42(42)
x2: Int = 42

See also SIP-23 about Literal-based Singleton Types.

Attributes

Supertypes
class Any
final case class Some[+A](value: A) extends Option[A]

Class Some[A] represents existing values of type A.

Class Some[A] represents existing values of type A.

Attributes

Source
Option.scala
Supertypes
class Option[A]
trait Serializable
trait Product
trait Equals
trait IterableOnce[A]
class Object
trait Matchable
class Any
Show all

A common supertype for companions of specializable types.

A common supertype for companions of specializable types. Should not be extended in user code.

Attributes

Companion
object
Source
Specializable.scala
Supertypes
class Object
trait Matchable
class Any
object Specializable

Attributes

Companion
trait
Source
Specializable.scala
Supertypes
class Object
trait Matchable
class Any
Self type
case class StringContext(parts: String*)

This class provides the basic mechanism to do String Interpolation.

This class provides the basic mechanism to do String Interpolation. String Interpolation allows users to embed variable references directly in *processed* string literals. Here's an example:

val name = "James"
println(s"Hello, $name")  // Hello, James

Any processed string literal is rewritten as an instantiation and method call against this class. For example:

s"Hello, $name"

is rewritten to be:

StringContext("Hello, ", "").s(name)

By default, this class provides the raw, s and f methods as available interpolators.

To provide your own string interpolator, create an implicit class which adds a method to StringContext. Here's an example:

implicit class JsonHelper(private val sc: StringContext) extends AnyVal {
  def json(args: Any*): JSONObject = ...
}
val x: JSONObject = json"{ a: $a }"

Here the JsonHelper extension class implicitly adds the json method to StringContext which can be used for json string literals.

Value parameters

parts

The parts that make up the interpolated string, without the expressions that get inserted by interpolation.

Attributes

Companion
object
Source
StringContext.scala
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
object StringContext

Attributes

Companion
class
Source
StringContext.scala
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type
final class Symbol extends Serializable

This class provides a simple way to get unique objects for equal strings.

This class provides a simple way to get unique objects for equal strings. Since symbols are interned, they can be compared using reference equality.

Attributes

Companion
object
Source
Symbol.scala
Supertypes
trait Serializable
class Object
trait