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 util
    Definition Classes
    scala
  • object Either extends java.io.Serializable
    Definition Classes
    util
  • LeftProjection
  • MergeableEither
  • RightProjection
c

scala.util.Either

LeftProjection

final case class LeftProjection[+A, +B](e: Either[A, B]) extends Product with Serializable

Projects an Either into a Left.

Source
Either.scala
See also

scala.util.Either#left

Linear Supertypes
java.io.Serializable, Product, Equals, AnyRef, Any
Type Hierarchy
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. LeftProjection
  2. Serializable
  3. Product
  4. Equals
  5. AnyRef
  6. Any
Implicitly
  1. by any2stringadd
  2. by StringFormat
  3. by Ensuring
  4. by ArrowAssoc
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Instance Constructors

  1. new LeftProjection(e: Either[A, B])

Value Members

  1. val e: Either[A, B]
  2. def exists(p: (A) => Boolean): Boolean

    Returns false if Right or returns the result of the application of the given function to the Left value.

    Returns false if Right or returns the result of the application of the given function to the Left value.

    Left(12).left.exists(_ > 10)  // true
    Left(7).left.exists(_ > 10)   // false
    Right(12).left.exists(_ > 10) // false
  3. def filterToOption[B1](p: (A) => Boolean): Option[Either[A, B1]]

    Returns None if this is a Right or if the given predicate p does not hold for the left value, otherwise, returns a Left.

    Returns None if this is a Right or if the given predicate p does not hold for the left value, otherwise, returns a Left.

    Left(12).left.filterToOption(_ > 10)  // Some(Left(12))
    Left(7).left.filterToOption(_ > 10)   // None
    Right(12).left.filterToOption(_ > 10) // None
  4. def flatMap[A1, B1 >: B](f: (A) => Either[A1, B1]): Either[A1, B1]

    Binds the given function across Left.

    Binds the given function across Left.

    Left(12).left.flatMap(x => Left("scala")) // Left("scala")
    Right(12).left.flatMap(x => Left("scala")) // Right(12)
    f

    The function to bind across Left.

  5. def forall(p: (A) => Boolean): Boolean

    Returns true if Right or returns the result of the application of the given function to the Left value.

    Returns true if Right or returns the result of the application of the given function to the Left value.

    Left(12).left.forall(_ > 10)  // true
    Left(7).left.forall(_ > 10)   // false
    Right(12).left.forall(_ > 10) // true
  6. def foreach[U](f: (A) => U): Unit

    Executes the given side-effecting function if this is a Left.

    Executes the given side-effecting function if this is a Left.

    Left(12).left.foreach(x => println(x))  // prints "12"
    Right(12).left.foreach(x => println(x)) // doesn't print
    f

    The side-effecting function to execute.

  7. def getOrElse[A1 >: A](or: => A1): A1

    Returns the value from this Left or the given argument if this is a Right.

    Returns the value from this Left or the given argument if this is a Right.

    Left(12).left.getOrElse(17)  // 12
    Right(12).left.getOrElse(17) // 17
  8. def map[A1](f: (A) => A1): Either[A1, B]

    Maps the function argument through Left.

    Maps the function argument through Left.

    Left(12).left.map(_ + 2) // Left(14)
    Right[Int, Int](12).left.map(_ + 2) // Right(12)
  9. 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
  10. def toOption: Option[A]

    Returns a Some containing the Left value if it exists or a None if this is a Right.

    Returns a Some containing the Left value if it exists or a None if this is a Right.

    Left(12).left.toOption // Some(12)
    Right(12).left.toOption // None
  11. def toSeq: Seq[A]

    Returns a Seq containing the Left value if it exists or an empty Seq if this is a Right.

    Returns a Seq containing the Left value if it exists or an empty Seq if this is a Right.

    Left(12).left.toSeq // Seq(12)
    Right(12).left.toSeq // Seq()

Deprecated Value Members

  1. def filter[B1](p: (A) => Boolean): Option[Either[A, B1]]

    Returns None if this is a Right or if the given predicate p does not hold for the left value, otherwise, returns a Left.

    Returns None if this is a Right or if the given predicate p does not hold for the left value, otherwise, returns a Left.

    Left(12).left.filter(_ > 10)  // Some(Left(12))
    Left(7).left.filter(_ > 10)   // None
    Right(12).left.filter(_ > 10) // None
    Annotations
    @deprecated
    Deprecated

    (Since version 2.13.0) Use filterToOption, which more accurately reflects the return type

  2. def get: A

    Returns the value from this Left or throws java.util.NoSuchElementException if this is a Right.

    Returns the value from this Left or throws java.util.NoSuchElementException if this is a Right.

    Left(12).left.get  // 12
    Right(12).left.get // NoSuchElementException
    Annotations
    @deprecated
    Deprecated

    (Since version 2.13.0) use Either.swap.getOrElse instead

    Exceptions thrown

    java.util.NoSuchElementException if the projection is scala.util.Right