public abstract class Either<L,R> extends DataObject implements Value<java.lang.Object>
| Modifier and Type | Class and Description |
|---|---|
static class |
Either.Left<L,R> |
static class |
Either.Right<L,R> |
| Modifier and Type | Method and Description |
|---|---|
abstract <T> T |
fold(java.util.function.Function<L,T> foldLeft,
java.util.function.Function<R,T> foldRight)
Transforms a value and returns it
|
abstract L |
getLeft()
|
abstract <T extends java.lang.Throwable> |
getLeftOrThrow(java.util.function.Supplier<? extends T> exceptionSupplier)
|
abstract R |
getRight()
|
abstract <T extends java.lang.Throwable> |
getRightOrThrow(java.util.function.Supplier<? extends T> exceptionSupplier)
|
abstract <TL extends java.lang.Throwable,TR extends java.lang.Throwable> |
handle(ValueHandler<? super L,? extends TL> leftValueHandler,
ValueHandler<? super R,? extends TR> rightValueHandler)
|
abstract <T extends java.lang.Throwable> |
handleLeft(ValueHandler<? super L,? extends T> leftValueHandler)
|
abstract <T extends java.lang.Throwable> |
handleRight(ValueHandler<? super R,? extends T> rightValueHandler)
|
abstract <T extends java.lang.Throwable> |
ifLeftThrow(java.util.function.Function<L,? extends T> exceptionSupplier)
|
abstract <T extends java.lang.Throwable> |
ifRightThrow(java.util.function.Function<R,? extends T> exceptionSupplier)
|
abstract boolean |
isLeft()
|
abstract boolean |
isRight()
|
static <L,R> Either<L,R> |
left(L value)
|
abstract <L2,R2> Either<L2,R2> |
map(java.util.function.Function<L,L2> leftValueMapper,
java.util.function.Function<R,R2> rightValueMapper)
|
abstract <L2> Either<L2,R> |
mapLeft(java.util.function.Function<L,L2> leftValueMapper)
|
abstract <R2> Either<L,R2> |
mapRight(java.util.function.Function<R,R2> rightValueMapper)
|
static <L,R> Either<L,R> |
right(R value)
|
abstract Either<R,L> |
swap()
Swaps left and right value of an
Either |
abstract java.lang.Object |
value()
Returns left value if of type
Either.Left or right value if of type Either.Right |
equals, hashCode, toStringpublic static <L,R> Either<L,R> right(R value)
public static <L,R> Either<L,R> left(L value)
public abstract Either<R,L> swap()
EitherEither with swapped left and right valuespublic abstract L getLeft() throws java.util.NoSuchElementException
public abstract R getRight() throws java.util.NoSuchElementException
public abstract <T extends java.lang.Throwable> L getLeftOrThrow(java.util.function.Supplier<? extends T> exceptionSupplier) throws T extends java.lang.Throwable
Either is of type Left.
Throws Exception provided via exceptionSupplier if value is defined as Right Either.T - type of Exception that will be provided by exceptionSupplierexceptionSupplier - that should provide Exception in case of Right EitherEither is of type LeftT - Exception provided via exceptionSupplier if value is defined as Right Either.T extends java.lang.Throwablepublic abstract <T extends java.lang.Throwable> R getRightOrThrow(java.util.function.Supplier<? extends T> exceptionSupplier) throws T extends java.lang.Throwable
Either is of type Right.
Throws Exception provided via exceptionSupplier if value is defined as Left Either.T - type of Exception that will be provided by exceptionSupplierexceptionSupplier - that should provide Exception in case of Left EitherEither is of type RightT - Exception provided via exceptionSupplier if value is defined as Left Either.T extends java.lang.Throwablepublic abstract <L2,R2> Either<L2,R2> map(java.util.function.Function<L,L2> leftValueMapper, java.util.function.Function<R,R2> rightValueMapper)
public abstract <L2> Either<L2,R> mapLeft(java.util.function.Function<L,L2> leftValueMapper)
public abstract <R2> Either<L,R2> mapRight(java.util.function.Function<R,R2> rightValueMapper)
public abstract <T> T fold(java.util.function.Function<L,T> foldLeft, java.util.function.Function<R,T> foldRight)
public abstract <T extends java.lang.Throwable> Either<L,R> handleLeft(ValueHandler<? super L,? extends T> leftValueHandler) throws T extends java.lang.Throwable
public abstract <T extends java.lang.Throwable> Either<L,R> handleRight(ValueHandler<? super R,? extends T> rightValueHandler) throws T extends java.lang.Throwable
public abstract <TL extends java.lang.Throwable,TR extends java.lang.Throwable> Either<L,R> handle(ValueHandler<? super L,? extends TL> leftValueHandler, ValueHandler<? super R,? extends TR> rightValueHandler) throws TL extends java.lang.Throwable, TR extends java.lang.Throwable
leftValueHandler if value is defined as Left Either.
Executes provided rightValueHandler if value is defined as Right Either.TL - class of potential Throwable thrown by leftValueHandlerTR - class of potential Throwable thrown by rightValueHandlerleftValueHandler - action that is executed for Left EitherrightValueHandler - action that is executed for Right EitherEither to allow method chainingTL - in case the leftValueHandler throws TTR - in case the rightValueHandler throws TTL extends java.lang.Throwablepublic abstract <T extends java.lang.Throwable> Either<L,R> ifLeftThrow(java.util.function.Function<L,? extends T> exceptionSupplier) throws T extends java.lang.Throwable
Exception provided via exceptionSupplier if value is defined as Left Either.
The exceptionSupplier is ignored if value is defined as Right Either.T - type of Exception that will be provided by exceptionSupplierexceptionSupplier - that should provide Exception in case of Left EitherT - Exception provided via exceptionSupplier if value is defined as Left Either.T extends java.lang.Throwablepublic abstract <T extends java.lang.Throwable> Either<L,R> ifRightThrow(java.util.function.Function<R,? extends T> exceptionSupplier) throws T extends java.lang.Throwable
Exception provided via exceptionSupplier if value is defined as Right Either.
The exceptionSupplier is ignored if value is defined as Left Either.T - type of Exception that will be provided by exceptionSupplierexceptionSupplier - that should provide Exception in case of Right EitherT - Exception provided via exceptionSupplier if value is defined as Right EitherT extends java.lang.Throwablepublic abstract java.lang.Object value()
Either.Left or right value if of type Either.Right