Package io.codemodder
Class Either<L,R>
java.lang.Object
io.codemodder.Either<L,R>
An implementation of the Either monad. It holds a single value of two possible types.
-
Method Summary
Modifier and TypeMethodDescriptionIf it contains the left value, applies thePredicate
pred
and return anEither
containingorElse
if it fails.Appliesfunc
to the right value if present and returns anEither
containing the result.flatMapRight
(Function<R, Either<L, A>> func) Appliesfunc
to the right value if present and returns anEither
containing the result.static <L,
R> Either<L, R> fromOptional
(Optional<L> maybe, R orElse) getLeft()
Returns the left value, may benull
getRight()
Returns the right value, may benull
void
ifLeftOrElse
(Consumer<? super L> leftAction, Consumer<? super R> rightAction) <A> A
ifLeftOrElseGet
(Function<? super L, A> leftFunction, Function<? super R, A> rightFunction) boolean
isLeft()
Returnstrue
if the left value is present.boolean
isRight()
Returnstrue
if the right value is present.static <A,
B> Either<A, B> left
(A value) Returns anEither
containingvalue
as a left value.Appliesfunc
to the left value if present.Appliesfunc
to the left value if present.static <A,
B> Either<A, B> right
(B value) Returns anEither
containingvalue
as a right value.toString()
-
Method Details
-
isLeft
public boolean isLeft()Returnstrue
if the left value is present. -
isRight
public boolean isRight()Returnstrue
if the right value is present. -
getLeft
Returns the left value, may benull
-
getRight
Returns the right value, may benull
-
left
Returns anEither
containingvalue
as a left value. -
right
Returns anEither
containingvalue
as a right value. -
map
Appliesfunc
to the left value if present. -
flatMap
Appliesfunc
to the right value if present and returns anEither
containing the result. Otherwise returns anEither
containing the left value. -
mapRight
Appliesfunc
to the left value if present. -
flatMapRight
Appliesfunc
to the right value if present and returns anEither
containing the result. Otherwise returns anEither
containing the left value. -
fromOptional
-
filter
If it contains the left value, applies thePredicate
pred
and return anEither
containingorElse
if it fails. Otherwise do nothing -
ifLeftOrElse
-
ifLeftOrElseGet
-
toString
-