Packages

  • package root

    This is the documentation for the Scala standard library.

    This is the documentation for the Scala standard library.

    Package structure

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

    Notable packages include:

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

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

    • scala.reflect - Scala's reflection API (scala-reflect.jar)
    • scala.xml - XML parsing, manipulation, and serialization (scala-xml.jar)
    • scala.collection.parallel - Parallel collections (scala-parallel-collections.jar)
    • scala.util.parsing - Parser combinators (scala-parser-combinators.jar)
    • scala.swing - A convenient wrapper around Java's GUI framework called Swing (scala-swing.jar)

    Automatic imports

    Identifiers in the scala package and the scala.Predef object are always in scope by default.

    Some of these identifiers are type aliases provided as shortcuts to commonly used classes. For example, List is an alias for scala.collection.immutable.List.

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

    Definition Classes
    root
  • package scala

    Core Scala types.

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

    Definition Classes
    root
  • package annotation
    Definition Classes
    scala
  • package beans
    Definition Classes
    scala
  • package collection
    Definition Classes
    scala
  • package compat
    Definition Classes
    scala
  • package concurrent

    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 http://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 source = scala.io.Source.fromFile("/etc/dictionaries-common/words")
      source.toSeq.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")
    }
    Definition Classes
    scala
  • package io
    Definition Classes
    scala
  • AnsiColor
  • BufferedSource
  • Codec
  • LowPriorityCodecImplicits
  • Source
  • StdIn
  • package jdk
    Definition Classes
    scala
  • package math

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

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

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

    Definition Classes
    scala
    See also

    java.lang.Math

  • package ref
    Definition Classes
    scala
  • package reflect
    Definition Classes
    scala
  • package 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.

    Definition Classes
    scala
    Since

    2.9

  • package util
    Definition Classes
    scala

package io

Content Hierarchy
Ordering
  1. Alphabetic
Visibility
  1. Public
  2. All

Type Members

  1. trait AnsiColor extends AnyRef

    ANSI escape codes providing control over text formatting and color on supporting text terminals.

    ANSI escape codes providing control over text formatting and color on supporting text terminals.

    ANSI Style and Control Codes

    This group of escape codes provides control over text styling. For example, to turn on reverse video with bold and then turn off all styling embed these codes,

    import io.AnsiColor._
    
    object ColorDemo extends App {
    
      println(s"${REVERSED}${BOLD}Hello 1979!${RESET}")
    }

    Foreground and Background Colors

    Embedding ANSI color codes in text output will control the text foreground and background colors.

    ForegroundBackground
    BLACK BLACK_B
    RED RED_B
    GREEN GREEN_B
    YELLOW YELLOW_B
    BLUE BLUE_B
    MAGENTAMAGENTA_B
    CYAN CYAN_B
    WHITE WHITE_B

  2. class BufferedSource extends Source

    This object provides convenience methods to create an iterable representation of a source file.

  3. class Codec extends AnyRef

    A class for character encoding/decoding preferences.

  4. trait LowPriorityCodecImplicits extends AnyRef
  5. abstract class Source extends Iterator[Char] with Closeable

    An iterable representation of source data.

    An iterable representation of source data. It may be reset with the optional reset method.

    Subclasses must supply the underlying iterator.

    Error handling may be customized by overriding the report method.

    The current input and position, as well as the next character methods delegate to the positioner.

    The default positioner encodes line and column numbers in the position passed to report. This behavior can be changed by supplying a custom positioner.

Value Members

  1. object AnsiColor extends AnsiColor
  2. object Codec extends LowPriorityCodecImplicits
  3. object Source

    This object provides convenience methods to create an iterable representation of a source file.

  4. object StdIn extends StdIn

Ungrouped