RightProjection

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

Projects an Either into a Right.

Because Either is already right-biased, this class is not normally needed. (It is retained in the library for now for easy cross-compilation between Scala 2.11 and 2.12.)

Attributes

Deprecated
[Since version 2.13.0] Either is now right-biased, calls to `right` should be removed
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: B => Boolean): Boolean

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

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

Right(12).right.exists(_ > 10)  // true
Right(7).right.exists(_ > 10)   // false
Left(12).right.exists(_ > 10)   // false

Value parameters

p

the predicate to apply to the Right value

Attributes

Returns

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

Source
Either.scala
def filterToOption[A1](p: B => Boolean): Option[Either[A1, B]]

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

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

Right(12).right.filterToOption(_ > 10) // Some(Right(12))
Right(7).right.filterToOption(_ > 10)  // None
Left(12).right.filterToOption(_ > 10)  // None

Type parameters

A1

the left type of the resulting Either

Value parameters

p

the predicate to apply to the Right value

Attributes

Returns

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

Source
Either.scala
def flatMap[A1 >: A, B1](f: B => Either[A1, B1]): Either[A1, B1]

Binds the given function across Right.

Binds the given function across Right.

Type parameters

A1

the supertype of A used to widen the left type

B1

the right type of the resulting Either

Value parameters

f

the function to bind across Right

Attributes

Source
Either.scala
def forall(f: B => Boolean): Boolean

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

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

Right(12).right.forall(_ > 10) // true
Right(7).right.forall(_ > 10)  // false
Left(12).right.forall(_ > 10)  // true

Value parameters

f

the predicate to apply to the Right value

Attributes

Returns

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

Source
Either.scala
def foreach[U](f: B => U): Unit

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

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

Right(12).right.foreach(x => println(x)) // prints "12"
Left(12).right.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[B1 >: B](or: => B1): B1

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

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

Right(12).right.getOrElse(17) // 12
Left(12).right.getOrElse(17)  // 17

Type parameters

B1

the supertype of B used to widen the return type

Value parameters

or

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

Attributes

Returns

the Right value if present, otherwise or

Source
Either.scala
def map[B1](f: B => B1): Either[A, B1]

The given function is applied if this is a Right.

The given function is applied if this is a Right.

Right(12).right.map(x => "flower") // Result: Right("flower")
Left(12).right.map(x => "flower")  // Result: Left(12)

Type parameters

B1

the result type of the mapping function

Value parameters

f

the function to apply to the Right value

Attributes

Returns

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

Source
Either.scala
def toOption: Option[B]

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

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

Right(12).right.toOption // Some(12)
Left(12).right.toOption // None

Attributes

Returns

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

Source
Either.scala
def toSeq: Seq[B]

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

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

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

Attributes

Returns

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

Source
Either.scala

Deprecated methods

def filter[A1](p: B => Boolean): Option[Either[A1, B]]

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

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

Right(12).right.filter(_ > 10) // Some(Right(12))
Right(7).right.filter(_ > 10)  // None
Left(12).right.filter(_ > 10)  // None

Attributes

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

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

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

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

Attributes

Throws
NoSuchElementException

if the projection is Left.

Deprecated
[Since version 2.13.0] Use `Either.toOption.get` 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