Reference: https://www.vavr.io/vavr-docs/#_either
Reference: https://static.javadoc.io/io.vavr/vavr/0.9.2/io/vavr/control/Either.html
Either represents a value of two possible types. An
Either is either a Left or a Right. If the given
Either is a Right and projected to a Left, the Left
operations have no effect on the Right value. If the
given Either is a Left and projected to a Right, the
Right operations have no effect on the Left value. If
a Left is projected to a Left or a Right is projected
to a Right, the operations have an effect.
Note that Try<T> is isomorphic to Either<Throwable, T>.
By convention the success case is Right and the
failure is Left.
We provide description and tests for Either's methods.
Please refer my other github projects:
- https://github.com/mtumilowicz/java11-vavr-option
- https://github.com/mtumilowicz/java11-vavr-try because we won't provide examples to the similar methods described in the projects mentioned above.
<L,R> Either<L,R> left(L left)- Constructs aEither.Left<L,R> Either<L,R> right(R right)- Constructs aEither.Right<L,R> Either<L,R> narrow(Either<? extends L,? extends R> either)- Narrows a widenedEither<? extends L, ? extends R>toEither<L, R>by performing a type-safe cast.<L,R> Either<Seq<L>,Seq<R>> sequence(Iterable<? extends Either<? extends L,? extends R>> eithers)- Reduces manyEithersinto a singleEitherby transforming anIterable<Either<L, R>>into aEither<Seq<L>, Seq<R>>.<L,R> Either<L,Seq<R>> sequenceRight(Iterable<? extends Either<? extends L,? extends R>> eithers)- Reduces manyEithersinto a singleEitherby transforming anIterable<Either<L, R>>into aEither<L, Seq<R>>.
Either<X,Y> bimap(Function<? super L,? extends X> leftMapper, Function<? super R,? extends Y> rightMapper)- Maps either the left or the right side of this disjunction.boolean equals(Object o)Option<Either<L,R>> filter(Predicate<? super R> predicate)- if
LeftreturnsOption.of(this) - if
Rightand predicate is satisfied returnsOption.of(this) - if
Rightand predicate is not satisfied returnsOption.none()
- if
Either<L,U> flatMap(Function<? super R,? extends Either<L,? extends U>> mapper)- if
RightflatMaps - if
Leftreturns this
- if
U fold(Function<? super L,? extends U> leftMapper, Function<? super R,? extends U> rightMapper)- if
Rightmaps right value with rightMapper - if
Leftmaps left value with leftMapper
- if
R get()- if
Rightreturns value - if
LeftthrowsNoSuchElementException
- if
L getLeft()R getOrElseGet(Function<? super L,? extends R> other)- if
Rightreturns value - if
Leftreturns other
- if
<X extends Throwable> R getOrElseThrow(Function<? super L,X> exceptionFunction)- if
Rightreturns value - if
Leftthrows exception
- if
int hashCode()boolean isEmpty()` @Override default boolean isEmpty() { return isLeft(); }boolean isLeft()boolean isRight()Either.LeftProjection<L,R> left()Either.RightProjection<L,R> right()Either<L,U> map(Function<? super R,? extends U> mapper)- if
Rightmaps right value with mapper - if
Leftreturns this
- if
Either<U,R> mapLeft(Function<? super L,? extends U> leftMapper)Either<L,R> orElse(Either<? extends L,? extends R> other)- if
Rightreturns this - if
Leftreturns left mapped byother
- if
Either<L,R> orElse(Supplier<? extends Either<? extends L,? extends R>> supplier)void orElseRun(Consumer<? super L> action)- ifLeftruns actionEither<L,R> peek(Consumer<? super R> action)- ifRightruns actionEither<L,R> peekLeft(Consumer<? super L> action)ifLeftruns actionEither<R,L> swap()Converts aLeftto aRightand vice versa by wrapping the value in a new type.