L - The left type.R - The right type.public abstract class Either<L,R> extends Object
Either type (an explicit sum type for Java).| Modifier and Type | Class and Description |
|---|---|
static class |
Either.Left<L,R>
The
Left type. |
static class |
Either.Right<L,R>
The
Right type. |
| Modifier and Type | Method and Description |
|---|---|
<R2,B> Either<L,R2> |
bind(EitherBiFunction<L,R,B,R2> f,
B value)
Chains this either to a function that accepts its rights argument and an
additional argument and returns an Either.
|
<R2> Either<L,R2> |
bind(EitherFunction<L,R,R2> f)
Chains this either to a functions that accepts its right argument and
returns an Either.
|
void |
consume(EitherConsumer<L> leftConsumer,
EitherConsumer<R> rightConsumer)
Consumes this Either.
|
<X> X |
fold(Function<L,X> left,
Function<R,X> right)
Fold the either with functions handling the Left and the Right case.
|
L |
getLeft()
Returns the left value (if this is a left value).
|
R |
getRight()
Returns the right value (if this is a right value).
|
boolean |
isLeft()
Checks whether this
Either is a left value. |
boolean |
isRight()
Checks whether this
Either is a right value. |
static <L,R> Either<L,R> |
left(L value)
Creates a left value.
|
static <L,R> Either<L,R> |
left(L value,
Class<R> rightType)
Creates a left value.
|
<B,R2> Either<L,R2> |
map(BiFunction<R,B,R2> f,
B value)
Chains this either to an ordinary function.
|
<R2> Either<L,R2> |
map(Function<R,R2> f)
Chains this either to an ordinary function.
|
static <L,R> Either<L,R> |
right(R value)
Creates a right value.
|
static <L,R> Either<L,R> |
right(R value,
Class<L> leftType)
Creates a right value.
|
public static <L,R> Either<L,R> left(L value)
L - The left type.R - The right type.value - The value to encapsulate as left.public static <L,R> Either<L,R> left(L value, Class<R> rightType)
value - The value to encapsulate as left.rightType - The right type (to aid in type inference)public static <L,R> Either<L,R> right(R value)
L - The left type.R - The right type.value - The value to encapsulate as left.public static <L,R> Either<L,R> right(R value, Class<L> leftType)
value - The value to encapsulate as right.leftType - The right type (to aid in type inference)public boolean isLeft()
Either is a left value.public boolean isRight()
Either is a right value.public L getLeft()
UnsupportedOperationException - if this is not actually a Either.Left.public R getRight()
UnsupportedOperationException - if this is not actually a Either.Right.public final <R2> Either<L,R2> bind(EitherFunction<L,R,R2> f)
f - A function taking a value of the right type, producing an Either
value.public final <R2,B> Either<L,R2> bind(EitherBiFunction<L,R,B,R2> f, B value)
f - A function taking a value of the right type and an additional
value of an arbitrary type, producing an Either value.value - An additional value which will be supplied as seconds argument to
the function.public final <R2> Either<L,R2> map(Function<R,R2> f)
Either.right(3).chainOrdinary(a -> a + 1); // Right(4)
Either.left(3).chainOrdinary(a -> a + 1); // Left(3)
f - An ordinary function, accepting a value of the right type and
producing a new value.public final <B,R2> Either<L,R2> map(BiFunction<R,B,R2> f, B value)
f - An ordinary function, accepting a value of the right type and an
additional value, and producing a new value.value - An additional value of arbitrary type.public final void consume(EitherConsumer<L> leftConsumer, EitherConsumer<R> rightConsumer)
leftConsumer - rightConsumer - public <X> X fold(Function<L,X> left, Function<R,X> right)
left - Function handling the left case.right - Function handling the right case.Copyright © 2015. All rights reserved.