LeftProjection

scala.util.Either.LeftProjection
final case class LeftProjection[+A, +B](e: Either[A, B])

Projects an Either into a Left.

Type parameters

A

the type of the Left value

B

the type of the Right value

Value parameters

e

the Either value to project

Attributes

See also
Source
Either.scala
Graph
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Members list

Value members

Concrete methods

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

Value parameters

p

the predicate to apply to the Left value

Attributes

Returns

true if this is a Left and the predicate holds for its value

Source
Either.scala
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

Type parameters

B1

the right type of the resulting Either

Value parameters

p

the predicate to apply to the Left value

Attributes

Returns

Some(Left(value)) if this is a Left and the predicate holds, None otherwise

Source
Either.scala
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)

Type parameters

A1

the left type of the resulting Either

B1

the supertype of B used to widen the right type

Value parameters

f

the function to bind across Left

Attributes

Returns

the result of applying f if this is a Left, otherwise the unchanged Right

Source
Either.scala
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

Value parameters

p

the predicate to apply to the Left value

Attributes

Returns

true if this is a Right or the predicate holds for the Left value

Source
Either.scala
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

Type parameters

U

the return type of the side-effecting function (discarded)

Value parameters

f

the side-effecting function to execute

Attributes

Source
Either.scala
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

Type parameters

A1

the supertype of A used to widen the return type

Value parameters

or

the default value to return if this is a Right, evaluated lazily

Attributes

Returns

the Left value if present, otherwise or

Source
Either.scala
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)

Type parameters

A1

the result type of the mapping function

Value parameters

f

the function to apply to the Left value

Attributes

Returns

a new Either with the function applied if this is a Left, otherwise the unchanged Right

Source
Either.scala
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

Attributes

Returns

a Some containing the Left value, or None if this is a Right

Source
Either.scala
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()

Attributes

Returns

a Seq containing the Left value, or an empty Seq if this is a Right

Source
Either.scala

Deprecated methods

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

Attributes

Deprecated
[Since version 2.13.0] Use `filterToOption`, which more accurately reflects the return type
Source
Either.scala
def get: A

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

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

Left(12).left.get  // 12
Right(12).left.get // NoSuchElementException

Attributes

Throws
Deprecated
[Since version 2.13.0] use `Either.swap.getOrElse` instead
Source
Either.scala

Inherited methods

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

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

Attributes

Inherited from:
Product
Source
Product.scala

An iterator over all the elements of this product.

An iterator over all the elements of this product.

Attributes

Returns

in the default implementation, an Iterator[Any]

Inherited from:
Product
Source
Product.scala