Class OneOfN.Just<T1>
java.lang.Object
de.xima.fc.common.data.algebraic.OneOfN
de.xima.fc.common.data.algebraic.OneOfN.Just<T1>
- Type Parameters:
T1- Type of the value for the first case.
- All Implemented Interfaces:
Serializable
- Enclosing class:
OneOfN
Emulates a sum type consisting of 1 case.
- 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 TypeMethodDescriptionfirst()static <T1> OneOfN.Just<T1> first(T1 first) getValue()Checks which case applies and returns the value for that case.booleanisFirst()<R1> OneOfN.Just<R1> 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.JustMatcher<? extends R, ? super T1> 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> 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.JustMatcher<? extends R, ? super T1> 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> RtryMatch(IThrowingFunction<? super T1, ? extends R> first) 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
-
first
- Returns:
- The value of the first case, if a value exists for that case.
- Throws:
IllegalArgumentException- If the requested case is not present.
-
getValue
-
isFirst
public boolean isFirst()- Returns:
- Whether a value for the first case is present.
-
map
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 first case.- Parameters:
first- Mapping function for the first case.- Returns:
- The sum type with 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:
first- Mapping function for the first 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
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.
-
selectFirst
-
tryMatch
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:
first- Mapping function for the first 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.
-
first
- Type Parameters:
T1- Type of the value for the first case.- Parameters:
first- The value for the first case.- Returns:
- A new sum type with the value for the first case.
-