Test two objects for inequality.
Test two objects for inequality.
true
if !(this == that), false otherwise.
Equivalent to x.hashCode
except for boxed numeric types and null
.
Equivalent to x.hashCode
except for boxed numeric types and null
.
For numerics, it returns a hash value which is consistent
with value equality: if two value type instances compare
as true, then ## will produce the same hash value for each
of them.
For null
returns a hashcode where null.hashCode
throws a
NullPointerException
.
a hash value consistent with ==
The expression x == that
is equivalent to if (x eq null) that eq null else x.equals(that)
.
The expression x == that
is equivalent to if (x eq null) that eq null else x.equals(that)
.
the object to compare against this object for equality.
true
if the receiver object is equivalent to the argument; false
otherwise.
Cast the receiver object to be of type T0
.
Cast the receiver object to be of type T0
.
Note that the success of a cast at runtime is modulo Scala's erasure semantics.
Therefore the expression 1.asInstanceOf[String]
will throw a ClassCastException
at
runtime, while the expression List(1).asInstanceOf[List[String]]
will not.
In the latter example, because the type argument is erased as part of compilation it is
not possible to check whether the contents of the list are of the requested type.
the receiver object.
ClassCastException
if the receiver object is not an instance of the erasure of type T0
.
Create a copy of the receiver object.
Returns true
if this wrapper represents a left-biased Either
wrapping a Left
or a
right-biased Either
wrapping a Right
.
Returns true
if this wrapper represents a left-biased Either
wrapping a Left
or a
right-biased Either
wrapping a Right
. Returns false if the bias of this wrapper is not
consistent with the type of the target Either
.
It is safe to call get on a biased Either
for which conformsToBias
is true
.
It is safe to call xget on a biased Either
for which conformsToBias
is false
.
Tests whether the argument (arg0
) is a reference to the receiver object (this
).
Tests whether the argument (arg0
) is a reference to the receiver object (this
).
The eq
method implements an equivalence relation on
non-null instances of AnyRef
, and has three additional properties:
x
and y
of type AnyRef
, multiple invocations of
x.eq(y)
consistently returns true
or consistently returns false
.x
of type AnyRef
, x.eq(null)
and null.eq(x)
returns false
.null.eq(null)
returns true
. When overriding the equals
or hashCode
methods, it is important to ensure that their behavior is
consistent with reference equality. Therefore, if two objects are references to each other (o1 eq o2
), they
should be equal to each other (o1 == o2
) and they should hash to the same value (o1.hashCode == o2.hashCode
).
true
if the argument is a reference to the receiver object; false
otherwise.
The equality method for reference types.
Returns false
if the target right-biased Either
is a Left
or returns the result of the application of
the given function to the Right
value.
Returns false
if the target right-biased Either
is a Left
or returns the result of the application of
the given function to the Right
value.
Right(12).exists(_ > 10) // true Right(7).exists(_ > 10) // false Left(12).exists(_ > 10) // false
Called by the garbage collector on the receiver object when there are no more references to the object.
Called by the garbage collector on the receiver object when there are no more references to the object.
The details of when and if the finalize
method is invoked, as
well as the interaction between finalize
and non-local returns
and exceptions, are all platform dependent.
Binds the given function across Right
of athe target right-biased Either
.
Binds the given function across Right
of athe target right-biased Either
.
Left(12).flatMap(x => Left("scala")) // Left(12) Right(12).flatMap(x => Right("scala") // Right("scala")
The function to bind across Left
.
Returns true
if the target right-biased Either
is Left
or returns
the result of the application of the given function to the Right
value.
Returns true
if the target right-biased Either
is Left
or returns
the result of the application of the given function to the Right
value.
Right(12).forall(_ > 10) // true Right(7).forall(_ > 10) // false Left(12).forall(_ > 10) // true
Executes the given side-effecting function if the target right-biased Either
is a Right
.
Executes the given side-effecting function if the target right-biased Either
is a Right
.
Left(12).foreach(x => println(x)) // doesn't print Right(12).foreach(x => println(x)) // prints "12"
The side-effecting function to execute.
Returns string formatted according to given format
string.
Returns string formatted according to given format
string.
Format strings are as for String.format
(@see java.lang.String.format).
Returns the value if the target right-biased Either
is a Right
or
throws java.util.NoSuchElementException
if the target is a Left
.
Returns the value if the target right-biased Either
is a Right
or
throws java.util.NoSuchElementException
if the target is a Left
.
Left(12).get // NoSuchElementException Right(12).get // 12
java.util.NoSuchElementException
if the target is scala.util.Left
A representation that corresponds to the dynamic class of the receiver object.
A representation that corresponds to the dynamic class of the receiver object.
The nature of the representation is platform dependent.
a representation that corresponds to the dynamic class of the receiver object.
not specified by SLS as a member of AnyRef
Returns the value from the target right-biased Either
if it is a Right
,
or the argument or
if it is a Left
.
Returns the value from the target right-biased Either
if it is a Right
,
or the argument or
if it is a Left
.
Left(12).getOrElse(17) // 12 Right(12).getOrElse(17) // 17
The hashCode method for reference types.
Returns true
if this right-biased Either
is a Left
that contains the empty token, signifying empty.
Returns true
if this right-biased Either
is a Left
that contains the empty token, signifying empty. Returns false
for any other error or value.
Test whether the dynamic type of the receiver object is T0
.
Test whether the dynamic type of the receiver object is T0
.
Note that the result of the test is modulo Scala's erasure semantics.
Therefore the expression 1.isInstanceOf[String]
will return false
, while the
expression List(1).isInstanceOf[List[String]]
will return true
.
In the latter example, because the type argument is erased as part of compilation it is
not possible to check whether the contents of the list are of the specified type.
true
if the receiver object is an instance of erasure of type T0
; false
otherwise.
Returns true
when called on a wrapper representing a left-biased Either
, false
otherwise.
Returns true
when called on a wrapper representing a right-biased Either
, false
otherwise.
Maps the function argument through Right
of the target right-biased Either
.
Maps the function argument through Right
of the target right-biased Either
.
Left(12).map(_ + 2) // Left(12) Right(12).map(_ + 2) // Right(14)
Equivalent to !(this eq that)
.
Equivalent to !(this eq that)
.
true
if the argument is not a reference to the receiver object; false
otherwise.
Wakes up a single thread that is waiting on the receiver object's monitor.
Wakes up a single thread that is waiting on the receiver object's monitor.
not specified by SLS as a member of AnyRef
Wakes up all threads that are waiting on the receiver object's monitor.
Wakes up all threads that are waiting on the receiver object's monitor.
not specified by SLS as a member of AnyRef
If the target right-biased Either
is a Left
containing the empty token,
returns a Left
containing replacement
.
If the target right-biased Either
is a Left
containing the empty token,
returns a Left
containing replacement
. Otherwise returns the target Either
unchanged.
// with empty token Int -1 Left(12).replaceIfEmpty(99) // Left(12) Left(-1).replaceIfEmpty(99) // Left(99) Right(12).replaceIfEmpty(99) // Right(12) Right(-1).replaceIfEmpty(99) // Right(-1)
Returns a Some
containing the Right
value of the target right-biased Either
if it exists or a
None
if the target is a Left
.
Returns a Some
containing the Right
value of the target right-biased Either
if it exists or a
None
if the target is a Left
.
Left(12).toOption // None Right(12).toOption // Some(12)
Returns a Seq
containing the Right
value if it exists or an empty
Seq
if the target right-biased Either
is a Left
.
Returns a Seq
containing the Right
value if it exists or an empty
Seq
if the target right-biased Either
is a Left
.
Left(12).toSeq // Seq() Right(12).toSeq // Seq(12)
Creates a String representation of this object.
Creates a String representation of this object. The default representation is platform dependent. On the java platform it is the concatenation of the class name, "@", and the object's hashcode in hexadecimal.
a String representation of the object.
Returns the target right-biased Either
unchanged if it is a Right
and the predicate p
holds for its value, or if it is any Left
.
Returns the target right-biased Either
unchanged if it is a Right
and the predicate p
holds for its value, or if it is any Left
.
Returns a Left
containing the empty token if the target is a Right
but predicate p
fails to hold. If no empty token has been set, a java.util.NoSuchElementException
will
be thrown.
val RightBias = RightBias.withEmptyToken[Int](-1); import RightBias._ Left(7).withFilter(_ > 10) // Left(7) Right(7).withFilter(_ > 10) // Left(-1) Right(12).withFilter(_ > 10) // Right(12)
"cross-get" -- Returns the value if the target right-biased Either
does not conform to its bias, that is, if it is a Left
.
"cross-get" -- Returns the value if the target right-biased Either
does not conform to its bias, that is, if it is a Left
.
Throws java.util.NoSuchElementException
if the target is a Right
.
Left(12).xget // 12 Right(12).xget // NoSuchElementException
java.util.NoSuchElementException
if the target is scala.util.Right
"cross-getOrElse" -- Returns the value from the target right-biased Either
if it does not conform to its bias and is a Left
.
"cross-getOrElse" -- Returns the value from the target right-biased Either
if it does not conform to its bias and is a Left
.
Returns the argument or
if it is a Right
.
Right(12).xgetOrElse(17) // 17 Left(12).xgetOrElse(17) // 12
"cross-map" -- Maps the function argument through Left
against the bias the target right-biased Either
.
"cross-map" -- Maps the function argument through Left
against the bias the target right-biased Either
.
Left(12).map(_ + 2) // Left(14) Right(12).map(_ + 2) // Right(12)
Implements the operations of a right-biased
Either
, whose specific behavior -- especially with respect to handling of an empty value resulting from a filter or failed pattern match -- is defined by constructor argumentopsTypeClass
.Clients can extend this is they wish to defined specialized right-biased
Either
instances that define extra operations.For more, see RightBias.