public interface Either<L,R>
Modifier and Type | Interface and Description |
---|---|
static class |
Either.Left<L,R>
Implementation of left.
|
static class |
Either.Right<L,R>
Implementation of right.
|
Modifier and Type | Method and Description |
---|---|
default void |
accept(Consumer<? super L> left,
Consumer<? super R> right)
Accepts either the left or the right consumer as appropriate.
|
default 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.
|
default Optional<L> |
asOptionalLeft()
Returns the left side as an Optional.
|
default 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.
|
default <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.
|
L |
getLeft()
Returns the left side.
|
R |
getRight()
Returns the right side.
|
default void |
ifLeft(Consumer<? super L> consumer)
Performs the given action if this is a Left.
|
default void |
ifRight(Consumer<? super R> consumer)
Performs the given action if this is a Right.
|
boolean |
isLeft()
True if it's left.
|
default boolean |
isRight()
True if it's right.
|
default <T> Either<T,R> |
mapLeft(Function<? super L,? extends T> mapper) |
default <T> Either<L,T> |
mapRight(Function<? super R,? extends T> mapper) |
boolean isLeft()
default boolean isRight()
L getLeft()
R getRight()
default void ifLeft(Consumer<? super L> consumer)
default void ifRight(Consumer<? super R> consumer)
default <T> T fold(Function<? super L,? extends T> left, Function<? super R,? extends T> right)
default void accept(Consumer<? super L> left, Consumer<? super R> right)
default void acceptBoth(Consumer<? super L> left, Consumer<? super R> right, L defaultLeft, R defaultRight)
static <L,R> Either<L,R> create(L l, R r)
static <L,R> Either<L,R> createLeft(L l)
static <L,R> Either<L,R> createRight(R r)