Interface Either<A,B>
- All Known Implementing Classes:
Either.Left, Either.Right
An
Either is always either an instance of Either.Left or Either.Right effectively
giving a union type of two other types.-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic final recordstatic final record -
Method Summary
Modifier and TypeMethodDescriptiondefault <T> TGets a value from thisEither.default <T, E extends Throwable>
TgetOrThrow(Function<A, T> funcA, Function<B, ? extends E> funcB) Gets a value from thisEitherif it is aEither.Leftor throws an exception if it is aEither.Right.left()Gets the left value of thisEitherif this is aEither.Left.static <A,B> Either <A, B> left(A a) Creates a newEither.Lefteither.default <T,U> Either <T, U> Maps thisEitherwith different mapper functions depending on whether this is aEither.Leftor aEither.Right.Maps thisEitherif it is aEither.Left.Maps thisEitherif it is aEither.Right.right()Gets the right value of thisEitherif this is aEither.Right.static <A,B> Either <A, B> right(B b) Creates a newEither.Righteither.swap()Swaps the order of the elements.static <T> Either<T, RuntimeException> Executes the givenSupplierand returns aEither.Leftwith the result.
-
Method Details
-
left
Gets the left value of thisEitherif this is aEither.Left. -
right
Gets the right value of thisEitherif this is aEither.Right. -
swap
-
mapLeft
-
mapRight
-
map
Maps thisEitherwith different mapper functions depending on whether this is aEither.Leftor aEither.Right. -
get
-
getOrThrow
default <T, E extends Throwable> T getOrThrow(Function<A, T> funcA, Function<B, ? extends E> funcB) throws EGets a value from thisEitherif it is aEither.Leftor throws an exception if it is aEither.Right.- Throws:
E
-
left
Creates a newEither.Lefteither. -
right
Creates a newEither.Righteither. -
tryWith
Executes the givenSupplierand returns aEither.Leftwith the result. If the supplier throws an exception, returns aEither.Rightcontaining that exception.
-