public abstract class Either<L,R> extends Object
A minimal implementation of Either.
Modifier and Type | Method and Description |
---|---|
void |
accept(Consumer<? super L> left,
Consumer<? super R> right)
Accepts either the left or the right consumer as appropriate.
|
void |
acceptBoth(Consumer<? super L> left,
Consumer<? super R> right,
L defaultLeft,
R defaultRight)
Accepts both the left and right consumers, using the default values to set the empty side.
|
Optional<L> |
asOptionalLeft()
Returns the left side as an Optional.
|
Optional<R> |
asOptionalRight()
Returns the right side as an Optional.
|
static <L,R> Either<L,R> |
create(L l,
R r)
Creates a left or right, depending on which element is non-null.
|
static <L,R> Either<L,R> |
createLeft(L l)
Creates an instance of Left.
|
static <L,R> Either<L,R> |
createRight(R r)
Creates an instance of Right.
|
<T> T |
fold(Function<? super L,? extends T> left,
Function<? super R,? extends T> right)
Applies either the left or the right function as appropriate.
|
abstract L |
getLeft()
Returns the left side.
|
abstract R |
getRight()
Returns the right side.
|
void |
ifLeft(Consumer<? super L> consumer)
Performs the given action if this is a Left.
|
void |
ifRight(Consumer<? super R> consumer)
Performs the given action if this is a Right.
|
abstract boolean |
isLeft()
True if it’s left.
|
boolean |
isRight()
True if it’s right.
|
<T> Either<T,R> |
mapLeft(Function<? super L,? extends T> mapper) |
<T> Either<L,T> |
mapRight(Function<? super R,? extends T> mapper) |
public abstract boolean isLeft()
True if it’s left.
public final boolean isRight()
True if it’s right.
public abstract L getLeft()
Returns the left side. Throws an exception if it’s really a Right.
public abstract R getRight()
Returns the right side. Throws an exception if it’s really a Left.
public final void ifLeft(Consumer<? super L> consumer)
Performs the given action if this is a Left.
public final void ifRight(Consumer<? super R> consumer)
Performs the given action if this is a Right.
public final <T> T fold(Function<? super L,? extends T> left, Function<? super R,? extends T> right)
Applies either the left or the right function as appropriate.
public final void accept(Consumer<? super L> left, Consumer<? super R> right)
Accepts either the left or the right consumer as appropriate.
public final void acceptBoth(Consumer<? super L> left, Consumer<? super R> right, @Nullable L defaultLeft, @Nullable R defaultRight)
Accepts both the left and right consumers, using the default values to set the empty side.
public static <L,R> Either<L,R> create(@Nullable L l, @Nullable R r)
Creates a left or right, depending on which element is non-null. Precisely one element should be non-null.
public static <L,R> Either<L,R> createLeft(L l)
Creates an instance of Left.
public static <L,R> Either<L,R> createRight(R r)
Creates an instance of Right.