net.sf.staccatocommons.lang.tuple
Class Tuples

java.lang.Object
  extended by net.sf.staccatocommons.lang.tuple.Tuples

public class Tuples
extends Object

Class methods hub for creating AbstractTuples, and obtaining Tuple-related functions

Author:
flbulgarelli

Constructor Summary
Tuples()
           
 
Method Summary
static
<T1,T2> net.sf.staccatocommons.defs.tuple.Tuple2<T1,T2>
_(T1 first, T2 second)
          Creates a new Tuple2
static
<T1,T2,T3> net.sf.staccatocommons.defs.tuple.Tuple3<T1,T2,T3>
_(T1 first, T2 second, T3 third)
          Creates a new Tuple3
static
<T1,T2,T3,T4>
net.sf.staccatocommons.defs.tuple.Tuple4<T1,T2,T3,T4>
_(T1 first, T2 second, T3 third, T4 fourth)
          Creates a new Quadruple
static
<A,B,C> net.sf.staccatocommons.defs.function.Function<A,net.sf.staccatocommons.defs.tuple.Tuple2<B,C>>
branch(net.sf.staccatocommons.defs.Applicable<? super A,? extends B> function0, net.sf.staccatocommons.defs.Applicable<? super A,? extends C> function1)
          Answers a function that applies both given functions to its argument, and returns both results, as a Pair.
static
<A,B> net.sf.staccatocommons.defs.function.Function<A,net.sf.staccatocommons.defs.tuple.Tuple2<A,B>>
clone(net.sf.staccatocommons.defs.Applicable<? super A,? extends B> function0)
          Answers a function that returns a Tuple2 that contains the original function argument and the result of applying +------function0-----> >----+ +-------------------->
static
<A,B,C> net.sf.staccatocommons.defs.function.Function2<A,B,C>
curry(net.sf.staccatocommons.defs.function.Function<net.sf.staccatocommons.defs.tuple.Tuple2<A,B>,C> function)
          Curries the given function that takes a single Tuple2, by returning a new one that takes two arguments, one for each component of the pair
static
<A,B> net.sf.staccatocommons.defs.predicate.Predicate2<A,B>
curry(net.sf.staccatocommons.defs.predicate.Predicate<net.sf.staccatocommons.defs.tuple.Tuple2<A,B>> predicate)
          Curries the given predicate that takes a single Tuple2, by returning a new one that takes two arguments, one for each component of the pair
static
<A,B,C,D> net.sf.staccatocommons.defs.function.Function3<A,B,C,D>
curry3(net.sf.staccatocommons.defs.function.Function<net.sf.staccatocommons.defs.tuple.Tuple3<A,B,C>,D> function)
          Curries the given function that takes a single Tuple3, by returning a new one that takes three arguments, one for each component of the triple
static
<A> net.sf.staccatocommons.defs.function.Function<net.sf.staccatocommons.defs.partial.FirstAware<A>,A>
first()
          Answers a function that returns the first component of a tuple
static
<A> net.sf.staccatocommons.defs.function.Function<net.sf.staccatocommons.defs.partial.FourthAware<A>,A>
fourth()
          Answers a function that returns the fourth component of a tuple
static
<A,B,C> net.sf.staccatocommons.defs.function.Function<net.sf.staccatocommons.defs.tuple.Tuple2<A,B>,C>
merge(net.sf.staccatocommons.defs.Applicable<? super B,? extends C> function)
           
static
<A> net.sf.staccatocommons.defs.function.Function<net.sf.staccatocommons.defs.partial.SecondAware<A>,A>
second()
          Answers a function that returns the second component of a tuple
static
<A> net.sf.staccatocommons.defs.function.Function<net.sf.staccatocommons.defs.partial.ThirdAware<A>,A>
third()
          Answers a function that returns the third component of a tuple
static
<T1,T2> net.sf.staccatocommons.defs.function.Function2<T1,T2,net.sf.staccatocommons.defs.tuple.Tuple2<T1,T2>>
toTuple2()
          Answers a function that creates Tuple2s for its arguments
static
<T1,T2,T3> net.sf.staccatocommons.defs.function.Function3<T1,T2,T3,net.sf.staccatocommons.defs.tuple.Tuple3<T1,T2,T3>>
toTuple3()
          Answers a function that creates Tuple3s for its arguments
static
<A,B,C,D> net.sf.staccatocommons.defs.function.Function<net.sf.staccatocommons.defs.tuple.Tuple2<A,B>,net.sf.staccatocommons.defs.tuple.Tuple2<C,D>>
zip(net.sf.staccatocommons.defs.Applicable<? super A,? extends C> function0, net.sf.staccatocommons.defs.Applicable<? super B,? extends D> function1)
          Combines two functions into one that takes a pair and applies the first function to the first component, and the second function to the second component, and returns the pair of results.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Tuples

public Tuples()
Method Detail

first

@Constant
public static <A> net.sf.staccatocommons.defs.function.Function<net.sf.staccatocommons.defs.partial.FirstAware<A>,A> first()
Answers a function that returns the first component of a tuple

Type Parameters:
A - type of the first element
Returns:
a constant function

second

@Constant
public static <A> net.sf.staccatocommons.defs.function.Function<net.sf.staccatocommons.defs.partial.SecondAware<A>,A> second()
Answers a function that returns the second component of a tuple

Type Parameters:
A - type of the second element
Returns:
a constant function

third

@Constant
public static <A> net.sf.staccatocommons.defs.function.Function<net.sf.staccatocommons.defs.partial.ThirdAware<A>,A> third()
Answers a function that returns the third component of a tuple

Type Parameters:
A - type of the third element
Returns:
a constant function

fourth

@Constant
public static <A> net.sf.staccatocommons.defs.function.Function<net.sf.staccatocommons.defs.partial.FourthAware<A>,A> fourth()
Answers a function that returns the fourth component of a tuple

Type Parameters:
A - type of the fourth element
Returns:
a constant function

_

@NonNull
public static <T1,T2,T3,T4> net.sf.staccatocommons.defs.tuple.Tuple4<T1,T2,T3,T4> _(T1 first,
                                                                                            T2 second,
                                                                                            T3 third,
                                                                                            T4 fourth)
Creates a new Quadruple

Type Parameters:
T1 -
T2 -
T3 -
T4 -
Parameters:
first -
second -
third -
fourth -
Returns:
a new Quadruple. Non null.

_

@NonNull
public static <T1,T2,T3> net.sf.staccatocommons.defs.tuple.Tuple3<T1,T2,T3> _(T1 first,
                                                                                      T2 second,
                                                                                      T3 third)
Creates a new Tuple3

Type Parameters:
T1 -
T2 -
T3 -
Parameters:
first -
second -
third -
Returns:
a new Tuple3. Non null.

_

@NonNull
public static <T1,T2> net.sf.staccatocommons.defs.tuple.Tuple2<T1,T2> _(T1 first,
                                                                                T2 second)
Creates a new Tuple2

Type Parameters:
T1 -
T2 -
Parameters:
first -
second -
Returns:
a new Tuple2. Non null.

toTuple3

@Constant
public static <T1,T2,T3> net.sf.staccatocommons.defs.function.Function3<T1,T2,T3,net.sf.staccatocommons.defs.tuple.Tuple3<T1,T2,T3>> toTuple3()
Answers a function that creates Tuple3s for its arguments

Type Parameters:
T1 -
T2 -
Returns:
a new Function3

toTuple2

@Constant
public static <T1,T2> net.sf.staccatocommons.defs.function.Function2<T1,T2,net.sf.staccatocommons.defs.tuple.Tuple2<T1,T2>> toTuple2()
Answers a function that creates Tuple2s for its arguments

Type Parameters:
T1 -
T2 -
T3 -
Returns:
a new Function2

curry

public static <A,B,C> net.sf.staccatocommons.defs.function.Function2<A,B,C> curry(net.sf.staccatocommons.defs.function.Function<net.sf.staccatocommons.defs.tuple.Tuple2<A,B>,C> function)
Curries the given function that takes a single Tuple2, by returning a new one that takes two arguments, one for each component of the pair

Type Parameters:
A -
B -
C -
Parameters:
function - the function to curry
Returns:
a new Function2

curry3

public static <A,B,C,D> net.sf.staccatocommons.defs.function.Function3<A,B,C,D> curry3(net.sf.staccatocommons.defs.function.Function<net.sf.staccatocommons.defs.tuple.Tuple3<A,B,C>,D> function)
Curries the given function that takes a single Tuple3, by returning a new one that takes three arguments, one for each component of the triple

Type Parameters:
A -
B -
C -
Parameters:
function - the function to curry
Returns:
a new Function3

curry

public static <A,B> net.sf.staccatocommons.defs.predicate.Predicate2<A,B> curry(net.sf.staccatocommons.defs.predicate.Predicate<net.sf.staccatocommons.defs.tuple.Tuple2<A,B>> predicate)
Curries the given predicate that takes a single Tuple2, by returning a new one that takes two arguments, one for each component of the pair

Type Parameters:
A -
B -
C -
Parameters:
predicate - the function to curry
Returns:
a new Predicate2

zip

public static <A,B,C,D> net.sf.staccatocommons.defs.function.Function<net.sf.staccatocommons.defs.tuple.Tuple2<A,B>,net.sf.staccatocommons.defs.tuple.Tuple2<C,D>> zip(net.sf.staccatocommons.defs.Applicable<? super A,? extends C> function0,
                                                                                                                                                                       net.sf.staccatocommons.defs.Applicable<? super B,? extends D> function1)
Combines two functions into one that takes a pair and applies the first function to the first component, and the second function to the second component, and returns the pair of results. Functions get combined as in the following figure:
 
 >------function0----->
 
 >------function1----->
 
Example:
 zip(NumberTypes.add(10), NumberTypes.add(1)).apply(_(2,0))
 
Returns the tuple
 (12, 1)
 

Parameters:
function0 -
function1 -
Returns:
a new function that zips both given functions

merge

public static <A,B,C> net.sf.staccatocommons.defs.function.Function<net.sf.staccatocommons.defs.tuple.Tuple2<A,B>,C> merge(net.sf.staccatocommons.defs.Applicable<? super B,? extends C> function)

branch

public static <A,B,C> net.sf.staccatocommons.defs.function.Function<A,net.sf.staccatocommons.defs.tuple.Tuple2<B,C>> branch(net.sf.staccatocommons.defs.Applicable<? super A,? extends B> function0,
                                                                                                                            net.sf.staccatocommons.defs.Applicable<? super A,? extends C> function1)
Answers a function that applies both given functions to its argument, and returns both results, as a Pair. Functions get combined as in the following figure:
      +------function0----->
 >----+
      +------function1----->
 
Example:
 branch(NumberTypes.add(10), Compare.greaterThan(5)).apply(2)
 
Returns the tuple
 (12, false)
 

Type Parameters:
A -
B -
C -
Parameters:
function0 - the function whose result will be the first component of the tuple
function1 - the function whose result will be the second component of the tuple
Returns:
a new Function that "branches" its argument

clone

public static <A,B> net.sf.staccatocommons.defs.function.Function<A,net.sf.staccatocommons.defs.tuple.Tuple2<A,B>> clone(net.sf.staccatocommons.defs.Applicable<? super A,? extends B> function0)
Answers a function that returns a Tuple2 that contains the original function argument and the result of applying
      +------function0----->
 >----+
      +-------------------->
 

Type Parameters:
A -
B -
Parameters:
function0 -
Returns:
a new Function


Copyright © 2010-2012 Staccatocommons. All Rights Reserved.