Class Pair<A,B>

java.lang.Object
io.atlassian.fugue.Pair<A,B>
All Implemented Interfaces:
Serializable

public final class Pair<A,B> extends Object implements Serializable
Represents a pair of objects.
Since:
1.0
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static final int
     
    private final A
     
    private final B
     
    private static final long
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Pair(A left, B right)
    Constructor for Pair.
  • Method Summary

    Modifier and Type
    Method
    Description
    static <A,B> Pair<B,B>
    ap(Pair<A,A> aa, Pair<Function<A,B>, Function<A,B>> ff)
    Performs function application within an homogeneous pair (applicative functor pattern).
    <AA,BB> Pair<AA,BB>
    bimap(Function<? super A, ? extends AA> fLeft, Function<? super B, ? extends BB> fRight)
    Applies functions to each of the left and right values to produce a new pair.
    boolean
    <R> R
    fold(BiFunction<? super A, ? super B, R> f)
    Applies a function to left and right values to produce a single result.
    int
    Accessor method for the left value of the pair.
    <AA> Pair<AA,B>
    leftMap(Function<? super A, AA> fLeft)
    Applies a function to the left value to produce a new Pair.
    static <A> Function<Pair<A,?>, A>
    Function for accessing the left value of pairs.
    static <A,B> Pair<B,B>
    map(Pair<A,A> aa, Function<A,B> f)
    Apply a function to both elements of an homogeneous pair.
    static <A,B> Pair<A,B>
    pair(A left, B right)
    Factory method for static Pair growth.
    static <A,B> BiFunction<A, B, Pair<A,B>>
    Factory method for a Pair factory function.
    Accessor method for the right value of the pair.q
    <BB> Pair<A,BB>
    rightMap(Function<? super B, BB> fRight)
    Applies a function to the right value to produce a new Pair.
    static <B> Function<Pair<?,B>, B>
    Function for accessing the right value of pairs.
     
    static <A,B> Iterable<Pair<A,B>>
    zip(Iterable<A> as, Iterable<B> bs)
    Zips two iterables into a single iterable that produces pairs.
    static <A,B> Optional<Pair<A,B>>
    zip(Optional<A> oA, Optional<B> oB)
    Zips the two given optionals into an optional of a pair.

    Methods inherited from class Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      See Also:
    • HALF_WORD

      private static final int HALF_WORD
      See Also:
    • left

      private final A left
  • Constructor Details

    • Pair

      public Pair(A left, B right)
      Constructor for Pair.
      Parameters:
      left - value, cannot be null
      right - value, cannot be null
  • Method Details

    • pair

      public static <A,B> Pair<A,B> pair(A left, B right)
      Factory method for static Pair growth.
      Type Parameters:
      A - the left value type
      B - the right value type
      Parameters:
      left - value, cannot be null
      right - value, cannot be null
      Returns:
      the Pair containing the passed values
    • pairs

      public static <A,B> BiFunction<A, B, Pair<A,B>> pairs()
      Factory method for a Pair factory function.
      Type Parameters:
      A - the left value type
      B - the right value type
      Returns:
      a function that constructs Pairs
    • leftValue

      public static <A> Function<Pair<A,?>, A> leftValue()
      Function for accessing the left value of pairs.
      Type Parameters:
      A - the left value type
      Returns:
      a Function that given a Pair returns the left side value
      Since:
      1.1
    • rightValue

      public static <B> Function<Pair<?,B>, B> rightValue()
      Function for accessing the right value of pairs.
      Type Parameters:
      B - the right value type
      Returns:
      a Function that given a Pair returns the right side value
      Since:
      1.1
    • ap

      public static <A,B> Pair<B,B> ap(Pair<A,A> aa, Pair<Function<A,B>, Function<A,B>> ff)
      Performs function application within an homogeneous pair (applicative functor pattern).
      Parameters:
      aa - an homogeneous pair
      ff - The pair of functions to apply.
      Returns:
      A new pair after applying the given pair of functions through aa.
    • map

      public static <A,B> Pair<B,B> map(Pair<A,A> aa, Function<A,B> f)
      Apply a function to both elements of an homogeneous pair.
      Parameters:
      aa - an homogeneous pair
      f - function to apply to both elements of aa
      Returns:
      A new pair after applying the function to aa elements.
    • zip

      public static <A,B> Iterable<Pair<A,B>> zip(Iterable<A> as, Iterable<B> bs)
      Zips two iterables into a single iterable that produces pairs.
      Type Parameters:
      A - LHS type
      B - RHS type
      Parameters:
      as - left values
      bs - right values
      Returns:
      an iterable of pairs, only as long as the shortest input iterable.
      Since:
      1.1
    • zip

      public static <A,B> Optional<Pair<A,B>> zip(Optional<A> oA, Optional<B> oB)
      Zips the two given optionals into an optional of a pair.
      Type Parameters:
      A - the first type
      B - the second type
      Parameters:
      oA - the first optional
      oB - the second optional
      Returns:
      empty if either or both optionals are empty
      Since:
      4.6.0
    • left

      public A left()
      Accessor method for the left value of the pair.
      Returns:
      a A object.
    • right

      public B right()
      Accessor method for the right value of the pair.q
      Returns:
      a B object.
    • swap

      public Pair<B,A> swap()
      Returns:
      a new Pair wth the left and right values swapped.
      Since:
      6.1
    • fold

      public <R> R fold(BiFunction<? super A, ? super B, R> f)
      Applies a function to left and right values to produce a single result.
      Type Parameters:
      R - the result type
      Parameters:
      f - the function to apply to the values
      Returns:
      the result of the applied function
      Since:
      6.1
    • leftMap

      public <AA> Pair<AA,B> leftMap(Function<? super A, AA> fLeft)
      Applies a function to the left value to produce a new Pair.
      Type Parameters:
      AA - The type of the new left value
      Parameters:
      fLeft - the function to be applied to the left value
      Returns:
      A new Pair containing the new left value, and the existing right value
      Since:
      6.1
    • rightMap

      public <BB> Pair<A,BB> rightMap(Function<? super B, BB> fRight)
      Applies a function to the right value to produce a new Pair.
      Type Parameters:
      BB - The type of the new right value
      Parameters:
      fRight - the function to be applied to the right value
      Returns:
      A new Pair containing the existing left value, and the new right value
      Since:
      6.1
    • bimap

      public <AA,BB> Pair<AA,BB> bimap(Function<? super A, ? extends AA> fLeft, Function<? super B, ? extends BB> fRight)
      Applies functions to each of the left and right values to produce a new pair.
      Type Parameters:
      AA - the type of the new left value
      BB - the type of the new right value
      Parameters:
      fLeft - the function to be applied to the left value
      fRight - the function to be applied to the right value
      Returns:
      a new Pair containing the new left and right values
      Since:
      6.1
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object