Package de.xima.fc.common.data.algebraic
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
public static final class OneOfN.OneOf3<T1,T2,T3> extends OneOfN
Emulates a sum type consisting of 3 cases.- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class de.xima.fc.common.data.algebraic.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>
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
isLeft()
boolean
isMiddle()
boolean
isRight()
static <T1,T2,T3>
OneOfN.OneOf3<T1,T2,T3>left(T1 left)
<R> R
match(Function<T1,R> left, Function<T2,R> middle, Function<T3,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> R
match(R defaultValue, OneOfN.OneOf3Matcher<R,T1,T2,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.OneOfN.Either<T2,T3>
mergeFirst(Function<T1,T2> combiner)
Allows for a multi-stage reduce operation of the cases into a single value.OneOfN.Either<T1,T2>
mergeLast(Function<T3,T2> combiner)
Allows for a multi-stage reduce operation of the cases into a single value.static <T1,T2,T3>
OneOfN.OneOf3<T1,T2,T3>middle(T2 middle)
static <T1,T2,T3>
OneOfN.OneOf3<T1,T2,T3>right(T3 right)
Optional<T1>
selectLeft()
Optional<T2>
selectMiddle()
Optional<T3>
selectRight()
-
-
-
Method Detail
-
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.
-
match
public <R> R match(Function<T1,R> left, Function<T2,R> middle, Function<T3,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
public <R> R match(R defaultValue, OneOfN.OneOf3Matcher<R,T1,T2,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
public OneOfN.Either<T2,T3> mergeFirst(Function<T1,T2> combiner)
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
public OneOfN.Either<T1,T2> mergeLast(Function<T3,T2> combiner)
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.
-
selectLeft
public Optional<T1> selectLeft()
- Returns:
- The value of the left case, if a value exists for that case.
-
selectMiddle
public Optional<T2> selectMiddle()
- Returns:
- The value of the middle case, if a value exists for that case.
-
selectRight
public Optional<T3> selectRight()
- Returns:
- The value of the right case, if a value exists for that case.
-
left
public static <T1,T2,T3> OneOfN.OneOf3<T1,T2,T3> left(T1 left)
- Parameters:
left
- The value for the left case.- Returns:
- A new sum type with the value for the left case.
-
middle
public static <T1,T2,T3> OneOfN.OneOf3<T1,T2,T3> middle(T2 middle)
- Parameters:
middle
- The value for the middle case.- Returns:
- A new sum type with the value for the middle case.
-
right
public static <T1,T2,T3> OneOfN.OneOf3<T1,T2,T3> right(T3 right)
- Parameters:
right
- The value for the right case.- Returns:
- A new sum type with the value for the right case.
-
-