Package io.atlassian.fugue
Class Pair<A,B>
- java.lang.Object
-
- io.atlassian.fugue.Pair<A,B>
-
- All Implemented Interfaces:
java.io.Serializable
public final class Pair<A,B> extends java.lang.Object implements java.io.SerializableRepresents a pair of objects.- Since:
- 1.0
- See Also:
- Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <A,B>
Pair<B,B>ap(Pair<A,A> aa, Pair<java.util.function.Function<A,B>,java.util.function.Function<A,B>> ff)Performs function application within an homogeneous pair (applicative functor pattern).<AA,BB>
Pair<AA,BB>bimap(java.util.function.Function<? super A,? extends AA> fLeft, java.util.function.Function<? super B,? extends BB> fRight)Applies functions to each of the left and right values to produce a new pair.booleanequals(java.lang.Object o)<R> Rfold(java.util.function.BiFunction<? super A,? super B,R> f)Applies a function to left and right values to produce a single result.inthashCode()Aleft()Accessor method for the left value of the pair.<AA> Pair<AA,B>leftMap(java.util.function.Function<? super A,AA> fLeft)Applies a function to the left value to produce a new Pair.static <A> java.util.function.Function<Pair<A,?>,A>leftValue()Function for accessing the left value ofpairs.static <A,B>
Pair<B,B>map(Pair<A,A> aa, java.util.function.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>
java.util.function.BiFunction<A,B,Pair<A,B>>pairs()Factory method for a Pair factory function.Bright()Accessor method for the right value of the pair.q<BB> Pair<A,BB>rightMap(java.util.function.Function<? super B,BB> fRight)Applies a function to the right value to produce a new Pair.static <B> java.util.function.Function<Pair<?,B>,B>rightValue()Function for accessing the right value ofpairs.Pair<B,A>swap()java.lang.StringtoString()static <A,B>
java.lang.Iterable<Pair<A,B>>zip(java.lang.Iterable<A> as, java.lang.Iterable<B> bs)Zips two iterables into a single iterable that producespairs.static <A,B>
java.util.Optional<Pair<A,B>>zip(java.util.Optional<A> oA, java.util.Optional<B> oB)Zips the two given optionals into an optional of a pair.
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
HALF_WORD
private static final int HALF_WORD
- See Also:
- Constant Field Values
-
left
private final A left
-
right
private final B right
-
-
Method Detail
-
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 typeB- the right value type- Parameters:
left- value, cannot be nullright- value, cannot be null- Returns:
- the Pair containing the passed values
-
pairs
public static <A,B> java.util.function.BiFunction<A,B,Pair<A,B>> pairs()
Factory method for a Pair factory function.- Type Parameters:
A- the left value typeB- the right value type- Returns:
- a function that constructs Pairs
-
leftValue
public static <A> java.util.function.Function<Pair<A,?>,A> leftValue()
Function for accessing the left value ofpairs.- Type Parameters:
A- the left value type- Returns:
- a Function that given a
Pairreturns the left side value - Since:
- 1.1
-
rightValue
public static <B> java.util.function.Function<Pair<?,B>,B> rightValue()
Function for accessing the right value ofpairs.- Type Parameters:
B- the right value type- Returns:
- a Function that given a
Pairreturns the right side value - Since:
- 1.1
-
ap
public static <A,B> Pair<B,B> ap(Pair<A,A> aa, Pair<java.util.function.Function<A,B>,java.util.function.Function<A,B>> ff)
Performs function application within an homogeneous pair (applicative functor pattern).- Parameters:
aa- an homogeneous pairff- 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, java.util.function.Function<A,B> f)
Apply a function to both elements of an homogeneous pair.- Parameters:
aa- an homogeneous pairf- function to apply to both elements of aa- Returns:
- A new pair after applying the function to aa elements.
-
zip
public static <A,B> java.lang.Iterable<Pair<A,B>> zip(java.lang.Iterable<A> as, java.lang.Iterable<B> bs)
Zips two iterables into a single iterable that producespairs.- Type Parameters:
A- LHS typeB- RHS type- Parameters:
as- left valuesbs- right values- Returns:
- an
iterableof pairs, only as long as the shortest input iterable. - Since:
- 1.1
-
zip
public static <A,B> java.util.Optional<Pair<A,B>> zip(java.util.Optional<A> oA, java.util.Optional<B> oB)
Zips the two given optionals into an optional of a pair.- Type Parameters:
A- the first typeB- the second type- Parameters:
oA- the first optionaloB- 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.
-
fold
public <R> R fold(java.util.function.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(java.util.function.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(java.util.function.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(java.util.function.Function<? super A,? extends AA> fLeft, java.util.function.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 valueBB- the type of the new right value- Parameters:
fLeft- the function to be applied to the left valuefRight- 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 java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
-