public interface Either<L,R>
Either
are either an instance of Left
or Right
. Either
of the type Right
. Either<InputStream, String> either = new Right<>("Right is not Left");In contrast to
Try
and Option
the Either
cannot directly be used as a collection (i.e iterate over it). Either
is unbiased as to which of Left
, Right
it represents. Either
you as a developer have to decide to work with either the Left
or Right
side. Either
(Right
) instance exemplified above. isLeft()
and isRight()
will help you decide which side is represented. left()
or right()
will yield a biased projection for that side. RightProjection<InputStream, String> projection = either.right();
Modifier and Type | Method and Description |
---|---|
<T> T |
fold(java.util.function.Function<L,T> func_left,
java.util.function.Function<R,T> func_right)
|
default boolean |
isLeft()
|
boolean |
isRight()
|
default LeftProjection<L,R> |
left()
Returns a
LeftProjection for this instance. |
default RightProjection<L,R> |
right()
Returns a
RightProjection for this instance. |
Either<R,L> |
swap()
|
boolean isRight()
true
if this instance is Right
.default boolean isLeft()
true
if this instance is Left
.<T> T fold(java.util.function.Function<L,T> func_left, java.util.function.Function<R,T> func_right)
default RightProjection<L,R> right()
RightProjection
for this instance.default LeftProjection<L,R> left()
LeftProjection
for this instance.Copyright © 2016, Peter Nerg Apache License v2.0