Class OneOfN.Either<T1,T2>
java.lang.Object
de.xima.fc.api.rest.pub.client.form.OneOfN
de.xima.fc.api.rest.pub.client.form.OneOfN.Either<T1,T2>
- Type Parameters:
T1- Type of the value for the left case.T2- Type of the value for the right case.
- Enclosing class:
OneOfN
Emulates a sum type consisting of 2 cases.
-
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 TypeMethodDescriptionbooleanisLeft()booleanisRight()static <T1,T2> OneOfN.Either <T1, T2> left(T1 left) <R> RPerforms 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.EitherMatcher<R, T1, T2> 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<T1, 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.static <T1,T2> OneOfN.Either <T1, T2> right(T2 right)
-
Method Details
-
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:
left- Mapping function for the left 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:
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 to one by mapping the first to the second case via the given mapping function, then unwraps the resulting Just type.- Parameters:
combiner- Mapping function that transform the value of the first case into the second case.- Returns:
- The value of the only remaining case.
-
mergeLast
Allows for a multi-stage reduce operation of the cases into a single value. Reduces the number of cases to one by mapping the right to the left case via the given mapping function, then unwraps the resulting Just type.- Parameters:
combiner- Mapping function that transform the value of the right case into the left case.- Returns:
- A sum type with one less case.
-
selectLeft
-
isLeft
public boolean isLeft()- Returns:
- Whether a value for the left case is present.
-
selectRight
-
isRight
public boolean isRight()- Returns:
- Whether a value for the right case is present.
-
left
- Parameters:
left- The value for the left case.- Returns:
- A new sum type with the value for the left case.
-
right
- Parameters:
right- The value for the right case.- Returns:
- A new sum type with the value for the right case.
-