Packages

c

scala.util.Either

RightProjection

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

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.)

Source
Either.scala
Linear Supertypes
Serializable, java.io.Serializable, Product, Equals, AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. RightProjection
  2. Serializable
  3. Serializable
  4. Product
  5. Equals
  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. All

Instance Constructors

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

Value Members

  1. val e: Either[A, B]
  2. 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
  3. 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
  4. 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.

    f

    The function to bind across Right.

  5. 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
  6. 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
    f

    The side-effecting function to execute.

  7. def get: B

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

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

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

    java.util.NoSuchElementException if the projection is Left.

  8. 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
  9. 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)
  10. 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
  11. 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()