Package dev.voidframework.core.lang
Class Either<L,R>
java.lang.Object
dev.voidframework.core.lang.Either<L,R>
- Type Parameters:
L- Type of "Left" valueR- 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.voidApplies the right consumer.<U> UApplies the right function.static <L,R> Either<L, R> ofLeft(L left) Creates aEitherwith left value set.static <L,R> Either<L, R> ofRight(R right) Creates aEitherwith right value set.
-
Method Details
-
ofLeft
Creates aEitherwith left value set.- Type Parameters:
L- Type of "Left" valueR- Type of "Right" value- Parameters:
left- The "Left" value- Returns:
- The newly created Either
-
ofRight
Creates aEitherwith right value set.- Type Parameters:
L- Type of "Left" valueR- 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
Applies the right function.- Type Parameters:
U- The returned value type- Parameters:
leftFunction- The "Left" functionrightFunction- The "Right" function- Returns:
- The result of the applied function
-