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
  • case class StringContext(parts: String*) extends Product with Serializable

    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.

    parts

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

    Definition Classes
    scala
  • s

object s

Source
StringContext.scala
Linear Supertypes
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. s
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Value Members

  1. def unapplySeq(s: String): Option[Seq[String]]

    The simple string matcher.

    The simple string matcher.

    Attempts to match the input string to the given interpolated patterns via a naive globbing, that is the reverse of the simple interpolator.

    Here is an example usage:

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

    In this example, the string "James" ends up matching the location where the pattern $name is positioned, and thus ends up bound to that variable.

    Multiple matches are supported:

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

    And the s matcher can match an arbitrary pattern within the ${} block, for example:

    val TimeSplitter = "([0-9]+)[.:]([0-9]+)".r
    val s"The time is ${TimeSplitter(hours, mins)}" = "The time is 10.50"
    println(hours) // 10
    println(mins) // 50

    Here, we use the TimeSplitter regex within the s matcher, further splitting the matched string "10.50" into its constituent parts