Interface Tuple<T1,T2>

Type Parameters:
T1 - The type of the first value
T2 - 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:
  • Method Summary

    Modifier and Type
    Method
    Description
     
     
    <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)
     
     
    default Tuple<T2,T1>
     
    <R> R
    to(BiFunction<? super T1,? super T2,R> convertor)
    Convert this tuple to an instance of an arbitrary type.
  • Method Details

    • ofMapEntry

      static <T1, T2> Tuple<T1,T2> ofMapEntry(Map.Entry<T1,T2> mapEntry)
    • 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 element
      secondMapper - the function to apply to the second element
      Returns:
      the new tuple
    • swap

      default Tuple<T2,T1> swap()
      Returns:
      a new tuple with the same elements in swapped positions.
    • asTuple

      Tuple<T1,T2> asTuple()
      Specified by:
      asTuple in interface ViewableAsTuple<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