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 manyEithers
into a singleEither
by 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 manyEithers
into a singleEither
by 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
Left
returnsOption.of(this)
- if
Right
and predicate is satisfied returnsOption.of(this)
- if
Right
and predicate is not satisfied returnsOption.none()
- if
Either<L,U> flatMap(Function<? super R,? extends Either<L,? extends U>> mapper)
- if
Right
flatMaps - if
Left
returns this
- if
U fold(Function<? super L,? extends U> leftMapper, Function<? super R,? extends U> rightMapper)
- if
Right
maps right value with rightMapper - if
Left
maps left value with leftMapper
- if
R get()
- if
Right
returns value - if
Left
throwsNoSuchElementException
- if
L getLeft()
R getOrElseGet(Function<? super L,? extends R> other)
- if
Right
returns value - if
Left
returns other
- if
<X extends Throwable> R getOrElseThrow(Function<? super L,X> exceptionFunction)
- if
Right
returns value - if
Left
throws 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
Right
maps right value with mapper - if
Left
returns this
- if
Either<U,R> mapLeft(Function<? super L,? extends U> leftMapper)
Either<L,R> orElse(Either<? extends L,? extends R> other)
- if
Right
returns this - if
Left
returns left mapped byother
- if
Either<L,R> orElse(Supplier<? extends Either<? extends L,? extends R>> supplier)
void orElseRun(Consumer<? super L> action)
- ifLeft
runs actionEither<L,R> peek(Consumer<? super R> action)
- ifRight
runs actionEither<L,R> peekLeft(Consumer<? super L> action)
ifLeft
runs actionEither<R,L> swap()
Converts aLeft
to aRight
and vice versa by wrapping the value in a new type.