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 thePredicatepredand return anEithercontainingorElseif it fails.Appliesfuncto the right value if present and returns anEithercontaining the result.flatMapRight(Function<R, Either<L, A>> func) Appliesfuncto the right value if present and returns anEithercontaining the result.static <L,R> Either<L, R> fromOptional(Optional<L> maybe, R orElse) getLeft()Returns the left value, may benullgetRight()Returns the right value, may benullvoidifLeftOrElse(Consumer<? super L> leftAction, Consumer<? super R> rightAction) <A> AifLeftOrElseGet(Function<? super L, A> leftFunction, Function<? super R, A> rightFunction) booleanisLeft()Returnstrueif the left value is present.booleanisRight()Returnstrueif the right value is present.static <A,B> Either<A, B> left(A value) Returns anEithercontainingvalueas a left value.Appliesfuncto the left value if present.Appliesfuncto the left value if present.static <A,B> Either<A, B> right(B value) Returns anEithercontainingvalueas a right value.toString()
-
Method Details
-
isLeft
public boolean isLeft()Returnstrueif the left value is present. -
isRight
public boolean isRight()Returnstrueif the right value is present. -
getLeft
Returns the left value, may benull -
getRight
Returns the right value, may benull -
left
Returns anEithercontainingvalueas a left value. -
right
Returns anEithercontainingvalueas a right value. -
map
Appliesfuncto the left value if present. -
flatMap
Appliesfuncto the right value if present and returns anEithercontaining the result. Otherwise, returns anEithercontaining the left value. -
mapRight
Appliesfuncto the left value if present. -
flatMapRight
Appliesfuncto the right value if present and returns anEithercontaining the result. Otherwise, returns anEithercontaining the left value. -
fromOptional
-
filter
If it contains the left value, applies thePredicatepredand return anEithercontainingorElseif it fails. Otherwise do nothing -
ifLeftOrElse
-
ifLeftOrElseGet
-
toString
-