Packages

  • package root

    This is the documentation for the Scala standard library.

    This is the documentation for the Scala standard library.

    Package structure

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

    Notable packages include:

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

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

    Automatic imports

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

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

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

    Definition Classes
    root
  • package scala

    Core Scala types.

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

    Definition Classes
    root
  • package util
    Definition Classes
    scala
  • package control
    Definition Classes
    util
  • object TailCalls

    Methods exported by this object implement tail calls via trampolining.

    Methods exported by this object implement tail calls via trampolining. Tail calling methods have to return their result using done or call the next method using tailcall. Both return a TailRec object. The result of evaluating a tailcalling function can be retrieved from a Tailrec value using method result. Implemented as described in "Stackless Scala with Free Monads" https://blog.higher-order.com/assets/trampolines.pdf

    Here's a usage example:

    import scala.util.control.TailCalls._
    
    def isEven(xs: List[Int]): TailRec[Boolean] =
      if (xs.isEmpty) done(true) else tailcall(isOdd(xs.tail))
    
    def isOdd(xs: List[Int]): TailRec[Boolean] =
     if (xs.isEmpty) done(false) else tailcall(isEven(xs.tail))
    
    isEven((1 to 100000).toList).result
    
    def fib(n: Int): TailRec[Int] =
      if (n < 2) done(n) else for {
        x <- tailcall(fib(n - 1))
        y <- tailcall(fib(n - 2))
      } yield x + y
    
    fib(40).result
    Definition Classes
    control
  • Call
  • Cont
  • Done
  • TailRec

case class Done[A](value: A) extends TailRec[A] with Product with Serializable

Internal class representing the final result returned from a tailcalling computation

Attributes
protected
Source
TailCalls.scala
Type Hierarchy
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Done
  2. Serializable
  3. Product
  4. Equals
  5. TailRec
  6. AnyRef
  7. Any
Implicitly
  1. by any2stringadd
  2. by StringFormat
  3. by Ensuring
  4. by ArrowAssoc
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Instance Constructors

  1. new Done(value: A)

Value Members

  1. final def flatMap[B](f: (A) => TailRec[B]): TailRec[B]

    Continue the computation with f and merge the trampolining of this computation with that of f.

    Continue the computation with f and merge the trampolining of this computation with that of f.

    Definition Classes
    TailRec
  2. final def map[B](f: (A) => B): TailRec[B]

    Continue the computation with f.

    Continue the computation with f.

    Definition Classes
    TailRec
  3. def productElementNames: Iterator[String]

    An iterator over the names of all the elements of this product.

    An iterator over the names of all the elements of this product.

    Definition Classes
    Product
  4. final def result: A

    Returns the result of the tailcalling computation.

    Returns the result of the tailcalling computation.

    Definition Classes
    TailRec
    Annotations
    @tailrec()
  5. final def resume: scala.Either[() => TailRec[A], A]

    Returns either the next step of the tailcalling computation, or the result if there are no more steps.

    Returns either the next step of the tailcalling computation, or the result if there are no more steps.

    Definition Classes
    TailRec
    Annotations
    @tailrec()
  6. val value: A