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>
public interface Tuple<T1,T2> extends 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:
ViewableAsTuple
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description Tuple<T1,T2>asTuple()T1first()<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.<S1> Tuple<S1,T2>mapFirst(Function<? super T1,? extends S1> mapper)Create a new tuple by applying a function to the first element, and putting the result as the first element of the new tuple.<S2> Tuple<T1,S2>mapSecond(Function<? super T2,? extends S2> mapper)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)T2second()default Tuple<T2,T1>swap()<R> Rto(BiFunction<? super T1,? super T2,R> convertor)Convert this tuple to an instance of an arbitrary type.
-
-
-
Method Detail
-
of
static <T1,T2> Tuple<T1,T2> of(T1 first, T2 second)
-
first
T1 first()
- Returns:
- the first value
-
second
T2 second()
- Returns:
- the second value
-
mapFirst
<S1> Tuple<S1,T2> mapFirst(Function<? super T1,? extends S1> mapper)
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
<S2> Tuple<T1,S2> mapSecond(Function<? super T2,? extends S2> mapper)
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
-
asTuple
Tuple<T1,T2> asTuple()
- Specified by:
asTuplein interfaceViewableAsTuple<T1,T2>- Returns:
- this tuple instance.
-
to
<R> R to(BiFunction<? super T1,? super T2,R> convertor)
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
-
-