Package dev.voidframework.core.lang
Class Either<LEFT_TYPE,RIGHT_TYPE>
java.lang.Object
dev.voidframework.core.lang.Either<LEFT_TYPE,RIGHT_TYPE>
- Type Parameters:
LEFT_TYPE- Type of "Left" valueRIGHT_TYPE- Type of "Right" value
Represents a value of one or two possible types (a disjoint union).
-
Method Summary
Modifier and TypeMethodDescriptiongetLeft()Returns the "Left" value.getRight()Returns the "Right" value.booleanhasLeft()Checks if the "Left" value is set.booleanhasRight()Checks if the "Right" value is set.voidmatch(Consumer<LEFT_TYPE> leftConsumer, Consumer<RIGHT_TYPE> rightConsumer) Applies the right consumer.<RETURN_TYPE>
RETURN_TYPEmatch(Function<LEFT_TYPE, RETURN_TYPE> leftFunction, Function<RIGHT_TYPE, RETURN_TYPE> rightFunction) Applies the right function.static <LEFT_TYPE,RIGHT_TYPE>
Either<LEFT_TYPE,RIGHT_TYPE> ofLeft(LEFT_TYPE left) Creates aEitherwith left value set.static <LEFT_TYPE,RIGHT_TYPE>
Either<LEFT_TYPE,RIGHT_TYPE> ofRight(RIGHT_TYPE right) Creates aEitherwith right value set.
-
Method Details
-
ofLeft
Creates aEitherwith left value set.- Type Parameters:
LEFT_TYPE- Type of "Left" valueRIGHT_TYPE- Type of "Right" value- Parameters:
left- The "Left" value- Returns:
- The newly created Either
-
ofRight
Creates aEitherwith right value set.- Type Parameters:
LEFT_TYPE- Type of "Left" valueRIGHT_TYPE- Type of "Right" value- Parameters:
right- The "Right" value- Returns:
- The newly created Either
-
getLeft
Returns the "Left" value.- Returns:
- The "Left" value
-
getRight
Returns the "Right" value.- Returns:
- The "Right" value
-
hasLeft
public boolean hasLeft()Checks if the "Left" value is set.- Returns:
trueif the "Left" value is set, otherwise,false
-
hasRight
public boolean hasRight()Checks if the "Right" value is set.- Returns:
trueif the "Right" value is set, otherwise,false
-
match
Applies the right consumer.- Parameters:
leftConsumer- The "Left" consumerrightConsumer- The "Right" consumer
-
match
public <RETURN_TYPE> RETURN_TYPE match(Function<LEFT_TYPE, RETURN_TYPE> leftFunction, Function<RIGHT_TYPE, RETURN_TYPE> rightFunction) Applies the right function.- Type Parameters:
RETURN_TYPE- The returned value type- Parameters:
leftFunction- The "Left" functionrightFunction- The "Right" function- Returns:
- The result of the applied function
-