Package no.digipost.tuple
Interface Tuple<T1,T2>
- Type Parameters:
T1- The type of the first valueT2- The type of the second value
- All Superinterfaces:
ViewableAsTuple<T1,T2>
A tuple is a simple composition of two arbitrary values (objects). A tuple
captures no semantics of the two values, and they are only referred to as
"the first" and "the second" value.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionasTuple()first()<S1,S2> Tuple<S1, S2> Create a new tuple by applying a function to each element, and putting the results to corresponding positions in the new tuple.Create a new tuple by applying a function to the first element, and putting the result as the first element of the new tuple.Create a new tuple by applying a function to the second element, and putting the result as the second element of the new tuple.static <T1,T2> Tuple<T1, T2> of(T1 first, T2 second) static <T1,T2> Tuple<T1, T2> ofMapEntry(Map.Entry<T1, T2> mapEntry) second()swap()<R> Rto(BiFunction<? super T1, ? super T2, R> convertor) Convert this tuple to an instance of an arbitrary type.
-
Method Details
-
ofMapEntry
-
of
-
first
T1 first()- Returns:
- the first value
-
second
T2 second()- Returns:
- the second value
-
mapFirst
Create a new tuple by applying a function to the first element, and putting the result as the first element of the new tuple.- Parameters:
mapper- the function to apply to the first element- Returns:
- the new tuple
-
mapSecond
Create a new tuple by applying a function to the second element, and putting the result as the second element of the new tuple.- Parameters:
mapper- the function to apply to the second element- Returns:
- the new tuple
-
map
<S1,S2> Tuple<S1,S2> map(Function<? super T1, ? extends S1> firstMapper, Function<? super T2, ? extends S2> secondMapper) Create a new tuple by applying a function to each element, and putting the results to corresponding positions in the new tuple.- Parameters:
firstMapper- the function to apply to the first elementsecondMapper- the function to apply to the second element- Returns:
- the new tuple
-
swap
- Returns:
- a new tuple with the same elements in swapped positions.
-
asTuple
- Specified by:
asTuplein interfaceViewableAsTuple<T1,T2> - Returns:
- this tuple instance.
-
to
Convert this tuple to an instance of an arbitrary type.- Type Parameters:
R- The type of the resulting instance- Parameters:
convertor- the function used to convert the contained values to a resulting compound instance.- Returns:
- the result from the given function
-