Class OneOfN.OneOf3<T1,T2,T3>
java.lang.Object
de.xima.fc.common.data.algebraic.OneOfN
de.xima.fc.common.data.algebraic.OneOfN.OneOf3<T1,T2,T3>
- Type Parameters:
T1- Type of the value for the left case.T2- Type of the value for the middle case.T3- Type of the value for the right case.
- All Implemented Interfaces:
Serializable
- Enclosing class:
OneOfN
Emulates a sum type consisting of 3 cases.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class OneOfN
OneOfN.Either<T1,T2>, OneOfN.EitherMatcher<R, T1, T2>, OneOfN.Just<T1>, OneOfN.JustMatcher<R, T1>, OneOfN.None, OneOfN.NoneMatcher<R>, OneOfN.OneOf3<T1, T2, T3>, OneOfN.OneOf3Matcher<R, T1, T2, T3>, OneOfN.OneOf4<T1, T2, T3, T4>, OneOfN.OneOf4Matcher<R, T1, T2, T3, T4>, OneOfN.OneOf5<T1, T2, T3, T4, T5>, OneOfN.OneOf5Matcher<R, T1, T2, T3, T4, T5> -
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T1,T2, T3> OneOfN.OneOf3 <T1, T2, T3> firstNonNull(T1 t1, T2 t2, T3 t3) Returns the first non-null value of the two given values as a OneOf3 type.booleanisLeft()booleanisMiddle()booleanisRight()left()static <T1,T2, T3> OneOfN.OneOf3 <T1, T2, T3> left(T1 left) <R1,R2, R3> OneOfN.OneOf3 <R1, R2, R3> map(Function<? super T1, ? extends R1> left, Function<? super T2, ? extends R2> middle, Function<? super T3, ? extends R3> right) Maps this sum type to another sum type by invoking the mapping function for the matching case with the value of this sum type and returning the result.<R> Rmatch(OneOfN.OneOf3Matcher<? extends R, ? super T1, ? super T2, ? super T3> matcher) Performs a case match on this sum type by invoking the mapping function for the matching case with the value of this sum type and returning the result.<R> Rmatch(Function<? super T1, ? extends R> left, Function<? super T2, ? extends R> middle, Function<? super T3, ? extends R> right) Performs a case match on this sum type by invoking the mapping function for the matching case with the value of this sum type and returning the result.<R> Rmatch(R defaultValue, OneOfN.OneOf3Matcher<? extends R, ? super T1, ? super T2, ? super T3> matcher) Performs a case match on this sum type by invoking the mapping function for the matching case with the value of this sum type and returning the result.mergeFirst(Function<? super T1, ? extends T2> combiner) Allows for a multi-stage reduce operation of the cases into a single value.Allows for a multi-stage reduce operation of the cases into a single value.middle()static <T1,T2, T3> OneOfN.OneOf3 <T1, T2, T3> middle(T2 middle) right()static <T1,T2, T3> OneOfN.OneOf3 <T1, T2, T3> right(T3 right) <R> RtryMatch(IThrowingFunction<? super T1, ? extends R> left, IThrowingFunction<? super T2, ? extends R> middle, IThrowingFunction<? super T3, ? extends R> right) Performs a case match on this sum type by invoking the mapping function for the matching case with the value of this sum type and returning the result.
-
Method Details
-
isLeft
public boolean isLeft()- Returns:
- Whether a value for the left case is present.
-
isMiddle
public boolean isMiddle()- Returns:
- Whether a value for the middle case is present.
-
isRight
public boolean isRight()- Returns:
- Whether a value for the right case is present.
-
left
- Returns:
- The value of the left case, if a value exists for that case.
- Throws:
IllegalArgumentException- If the requested case is not present.
-
map
public <R1,R2, OneOfN.OneOf3<R1,R3> R2, mapR3> (Function<? super T1, ? extends R1> left, Function<? super T2, ? extends R2> middle, Function<? super T3, ? extends R3> right) Maps this sum type to another sum type by invoking the mapping function for the matching case with the value of this sum type and returning the result.- Type Parameters:
R1- Type of the result returned by the mapping function for the left case.R2- Type of the result returned by the mapping function for the middle case.R3- Type of the result returned by the mapping function for the- Parameters:
left- Mapping function for the left case.middle- Mapping function for the middle case.right- Mapping function for the right case.- Returns:
- The sum type with the value returned by the mapping function for the matching case.
-
match
public <R> R match(Function<? super T1, ? extends R> left, Function<? super T2, ? extends R> middle, Function<? super T3, ? extends R> right) Performs a case match on this sum type by invoking the mapping function for the matching case with the value of this sum type and returning the result.- Type Parameters:
R- Type of the result returned by each mapping function.- Parameters:
left- Mapping function for the left case.middle- Mapping function for the middle case.right- Mapping function for the right case.- Returns:
- The value returned by the mapping function for the matching case.
-
match
Performs a case match on this sum type by invoking the mapping function for the matching case with the value of this sum type and returning the result.- Type Parameters:
R- Type of the result returned by each mapping function.- Parameters:
matcher- Matcher object for each case.- Returns:
- The value returned by the mapping function for the matching case.
-
match
public <R> R match(R defaultValue, OneOfN.OneOf3Matcher<? extends R, ? super T1, ? super T2, ? super T3> matcher) Performs a case match on this sum type by invoking the mapping function for the matching case with the value of this sum type and returning the result.- Type Parameters:
R- Type of the result returned by each mapping function.- Parameters:
defaultValue- Value returned when the given matcher has no matching case.matcher- Matcher object for each case.- Returns:
- The value returned by the mapping function for the matching case.
-
mergeFirst
Allows for a multi-stage reduce operation of the cases into a single value. Reduces the number of cases by one by mapping the first to the second case via the given mapping function.- Parameters:
combiner- Mapping function that transform the value of the first case into the second case.- Returns:
- A sum type with one less case.
-
mergeLast
Allows for a multi-stage reduce operation of the cases into a single value. Reduces the number of cases by one by mapping the right to the middle case via the given mapping function.- Parameters:
combiner- Mapping function that transform the value of the right case into the middle case.- Returns:
- A sum type with one less case.
-
middle
- Returns:
- The value of the middle case, if a value exists for that case.
- Throws:
IllegalArgumentException- If the requested case is not present.
-
right
- Returns:
- The value of the right case, if a value exists for that case.
- Throws:
IllegalArgumentException- If the requested case is not present.
-
selectLeft
-
selectMiddle
-
selectRight
-
tryMatch
public <R> R tryMatch(IThrowingFunction<? super T1, ? extends R> left, IThrowingFunction<? super T2, ? extends R> middle, IThrowingFunction<? super T3, ? extends R> right) throws Exception Performs a case match on this sum type by invoking the mapping function for the matching case with the value of this sum type and returning the result.- Type Parameters:
R- Type of the result returned by each mapping function.- Parameters:
left- Mapping function for the left case.middle- Mapping function for the middle case.right- Mapping function for the right case.- Returns:
- The value returned by the mapping function for the matching case.
- Throws:
Exception- If the mapping function for the matching case throws an exception.
-
firstNonNull
Returns the first non-null value of the two given values as a OneOf3 type.- Type Parameters:
T1- Type of the value for the left case.T2- Type of the value for the middle case.T3- Type of the value for the right case.- Parameters:
t1- The first valuet2- The second valuet3- The third value- Returns:
- The first non-null value, or null if both are null.
-
left
- Type Parameters:
T1- Type of the value for the left case.T2- Type of the value for the middle case.T3- Type of the value for the right case.- Parameters:
left- The value for the left case.- Returns:
- A new sum type with the value for the left case.
-
middle
- Type Parameters:
T1- Type of the value for the left case.T2- Type of the value for the middle case.T3- Type of the value for the right case.- Parameters:
middle- The value for the middle case.- Returns:
- A new sum type with the value for the middle case.
-
right
- Type Parameters:
T1- Type of the value for the left case.T2- Type of the value for the middle case.T3- Type of the value for the right case.- Parameters:
right- The value for the right case.- Returns:
- A new sum type with the value for the right case.
-