final case class RightProjection[+A, +B](e: Either[A, B]) extends Product with Serializable
Projects an Either
into a Right
.
This allows for-comprehensions over Either instances - for example
for (s <- Right("flower").right) yield s.length // Right(6)
Continuing the analogy with scala.Option, a RightProjection
declares
that Right
should be analogous to Some
in some code.
Analogous to LeftProjection
, see example usage in its documentation above.
- Annotations
- @deprecated
- Deprecated
(Since version 2.12.0) Either is now right-biased
- Source
- Either.scala
- Version
1.0, 11/10/2008
- Alphabetic
- By Inheritance
- RightProjection
- Serializable
- Serializable
- Product
- Equals
- AnyRef
- Any
- by any2stringadd
- by StringFormat
- by Ensuring
- by ArrowAssoc
- Hide All
- Show All
- Public
- All
Value Members
- val e: Either[A, B]
-
def
exists(p: (B) ⇒ Boolean): Boolean
Returns
false
ifLeft
or returns the result of the application of the given function to theRight
value.Returns
false
ifLeft
or returns the result of the application of the given function to theRight
value.Right(12).right.exists(_ > 10) // true Right(7).right.exists(_ > 10) // false Left(12).right.exists(_ > 10) // false
-
def
filter[X](p: (B) ⇒ Boolean): Option[Either[X, B]]
Returns
None
if this is aLeft
or if the given predicatep
does not hold for the right value, otherwise, returns aRight
.Returns
None
if this is aLeft
or if the given predicatep
does not hold for the right value, otherwise, returns aRight
.Right(12).right.filter(_ > 10) // Some(Right(12)) Right(7).right.filter(_ > 10) // None Left(12).right.filter(_ > 10) // None
-
def
flatMap[AA >: A, Y](f: (B) ⇒ Either[AA, Y]): Either[AA, Y]
Binds the given function across
Right
.Binds the given function across
Right
.- f
The function to bind across
Right
.
-
def
forall(f: (B) ⇒ Boolean): Boolean
Returns
true
ifLeft
or returns the result of the application of the given function to theRight
value.Returns
true
ifLeft
or returns the result of the application of the given function to theRight
value.Right(12).right.forall(_ > 10) // true Right(7).right.forall(_ > 10) // false Left(12).right.forall(_ > 10) // true
-
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.
-
def
get: B
Returns the value from this
Right
or throwsjava.util.NoSuchElementException
if this is aLeft
.Returns the value from this
Right
or throwsjava.util.NoSuchElementException
if this is aLeft
.Right(12).right.get // 12 Left(12).right.get // NoSuchElementException
- Exceptions thrown
java.util.NoSuchElementException
if the projection isLeft
.
-
def
getOrElse[BB >: B](or: ⇒ BB): BB
Returns the value from this
Right
or the given argument if this is aLeft
.Returns the value from this
Right
or the given argument if this is aLeft
.Right(12).right.getOrElse(17) // 12 Left(12).right.getOrElse(17) // 17
-
def
map[Y](f: (B) ⇒ Y): Either[A, Y]
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)
-
def
toOption: Option[B]
Returns a
Some
containing theRight
value if it exists or aNone
if this is aLeft
.Returns a
Some
containing theRight
value if it exists or aNone
if this is aLeft
.Right(12).right.toOption // Some(12) Left(12).right.toOption // None
-
def
toSeq: Seq[B]
Returns a
Seq
containing theRight
value if it exists or an emptySeq
if this is aLeft
.Returns a
Seq
containing theRight
value if it exists or an emptySeq
if this is aLeft
.Right(12).right.toSeq // Seq(12) Left(12).right.toSeq // Seq()
This is the documentation for the Scala standard library.
Package structure
The scala package contains core types like
Int
,Float
,Array
orOption
which are accessible in all Scala compilation units without explicit qualification or imports.Notable packages include:
scala.collection
and its sub-packages contain Scala's collections frameworkscala.collection.immutable
- Immutable, sequential data-structures such asVector
,List
,Range
,HashMap
orHashSet
scala.collection.mutable
- Mutable, sequential data-structures such asArrayBuffer
,StringBuilder
,HashMap
orHashSet
scala.collection.concurrent
- Mutable, concurrent data-structures such asTrieMap
scala.collection.parallel.immutable
- Immutable, parallel data-structures such asParVector
,ParRange
,ParHashMap
orParHashSet
scala.collection.parallel.mutable
- Mutable, parallel data-structures such asParArray
,ParHashMap
,ParTrieMap
orParHashSet
scala.concurrent
- Primitives for concurrent programming such asFutures
andPromises
scala.io
- Input and output operationsscala.math
- Basic math functions and additional numeric types likeBigInt
andBigDecimal
scala.sys
- Interaction with other processes and the operating systemscala.util.matching
- Regular expressionsOther 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.swing
- A convenient wrapper around Java's GUI framework called Swing (scala-swing.jar)scala.util.parsing
- Parser combinators, including an example implementation of a JSON parser (scala-parser-combinators.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 forscala.collection.immutable.List
.Other aliases refer to classes provided by the underlying platform. For example, on the JVM,
String
is an alias forjava.lang.String
.