- java.lang.Object
-
- org.scijava.function.Functions
-
public final class Functions extends Object
Container class for higher-arityFunction-style functional interfaces—i.e. with functional methodapplywith a number of arguments corresponding to the arity.- For 0-arity (nullary) functions, use
Producer(and notice the functional method there is namedProducer.create()). - For 1-arity (unary) functions, use
Function. - For 2-arity (binary) functions, use
BiFunction.
- Author:
- Curtis Rueden, Gabriel Selzer
- For 0-arity (nullary) functions, use
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceFunctions.Arity10<I1,I2,I3,I4,I5,I6,I7,I8,I9,I10,O>A 10-arity specialization ofFunction.static interfaceFunctions.Arity11<I1,I2,I3,I4,I5,I6,I7,I8,I9,I10,I11,O>A 11-arity specialization ofFunction.static interfaceFunctions.Arity12<I1,I2,I3,I4,I5,I6,I7,I8,I9,I10,I11,I12,O>A 12-arity specialization ofFunction.static interfaceFunctions.Arity13<I1,I2,I3,I4,I5,I6,I7,I8,I9,I10,I11,I12,I13,O>A 13-arity specialization ofFunction.static interfaceFunctions.Arity14<I1,I2,I3,I4,I5,I6,I7,I8,I9,I10,I11,I12,I13,I14,O>A 14-arity specialization ofFunction.static interfaceFunctions.Arity15<I1,I2,I3,I4,I5,I6,I7,I8,I9,I10,I11,I12,I13,I14,I15,O>A 15-arity specialization ofFunction.static interfaceFunctions.Arity16<I1,I2,I3,I4,I5,I6,I7,I8,I9,I10,I11,I12,I13,I14,I15,I16,O>A 16-arity specialization ofFunction.static interfaceFunctions.Arity3<I1,I2,I3,O>A 3-arity specialization ofFunction.static interfaceFunctions.Arity4<I1,I2,I3,I4,O>A 4-arity specialization ofFunction.static interfaceFunctions.Arity5<I1,I2,I3,I4,I5,O>A 5-arity specialization ofFunction.static interfaceFunctions.Arity6<I1,I2,I3,I4,I5,I6,O>A 6-arity specialization ofFunction.static interfaceFunctions.Arity7<I1,I2,I3,I4,I5,I6,I7,O>A 7-arity specialization ofFunction.static interfaceFunctions.Arity8<I1,I2,I3,I4,I5,I6,I7,I8,O>A 8-arity specialization ofFunction.static interfaceFunctions.Arity9<I1,I2,I3,I4,I5,I6,I7,I8,I9,O>A 9-arity specialization ofFunction.static interfaceFunctions.ArityN<O>
-
Field Summary
Fields Modifier and Type Field Description static HashMap<Class<?>,Integer>ALL_ARITIESstatic HashMap<Integer,Class<?>>ALL_FUNCTIONSAll known function types and their arities.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static intarityOf(Class<?> c)static Class<?>functionOfArity(int arity)static booleanisFunction(Class<?> c)static <O> Functions.ArityN<O>nary(BiFunction<?,?,O> f)Converts aBiFunctionto aFunctions.ArityN.static <O> Functions.ArityN<O>nary(Function<?,O> f)Converts aFunctionto aFunctions.ArityN.static <O> Functions.ArityN<O>nary(Functions.Arity10<?,?,?,?,?,?,?,?,?,?,O> f)Converts aFunctions.Arity10to aFunctions.ArityN.static <O> Functions.ArityN<O>nary(Functions.Arity11<?,?,?,?,?,?,?,?,?,?,?,O> f)Converts aFunctions.Arity11to aFunctions.ArityN.static <O> Functions.ArityN<O>nary(Functions.Arity12<?,?,?,?,?,?,?,?,?,?,?,?,O> f)Converts aFunctions.Arity12to aFunctions.ArityN.static <O> Functions.ArityN<O>nary(Functions.Arity13<?,?,?,?,?,?,?,?,?,?,?,?,?,O> f)Converts aFunctions.Arity13to aFunctions.ArityN.static <O> Functions.ArityN<O>nary(Functions.Arity14<?,?,?,?,?,?,?,?,?,?,?,?,?,?,O> f)Converts aFunctions.Arity14to aFunctions.ArityN.static <O> Functions.ArityN<O>nary(Functions.Arity15<?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,O> f)Converts aFunctions.Arity15to aFunctions.ArityN.static <O> Functions.ArityN<O>nary(Functions.Arity16<?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,O> f)Converts aFunctions.Arity16to aFunctions.ArityN.static <O> Functions.ArityN<O>nary(Functions.Arity3<?,?,?,O> f)Converts aFunctions.Arity3to aFunctions.ArityN.static <O> Functions.ArityN<O>nary(Functions.Arity4<?,?,?,?,O> f)Converts aFunctions.Arity4to aFunctions.ArityN.static <O> Functions.ArityN<O>nary(Functions.Arity5<?,?,?,?,?,O> f)Converts aFunctions.Arity5to aFunctions.ArityN.static <O> Functions.ArityN<O>nary(Functions.Arity6<?,?,?,?,?,?,O> f)Converts aFunctions.Arity6to aFunctions.ArityN.static <O> Functions.ArityN<O>nary(Functions.Arity7<?,?,?,?,?,?,?,O> f)Converts aFunctions.Arity7to aFunctions.ArityN.static <O> Functions.ArityN<O>nary(Functions.Arity8<?,?,?,?,?,?,?,?,O> f)Converts aFunctions.Arity8to aFunctions.ArityN.static <O> Functions.ArityN<O>nary(Functions.Arity9<?,?,?,?,?,?,?,?,?,O> f)Converts aFunctions.Arity9to aFunctions.ArityN.static <O> Functions.ArityN<O>nary(Producer<O> f)Converts aProducerto aFunctions.ArityN.static Class<?>superType(Class<?> c)
-
-
-
Field Detail
-
ALL_FUNCTIONS
public static final HashMap<Integer,Class<?>> ALL_FUNCTIONS
All known function types and their arities. The entries are sorted by arity, i.e., thei-th entry has an arity ofi. It might be nice to use a BiMap from e.g. Google Guava, but that would require a dependency on that component :(
-
-
Method Detail
-
isFunction
public static boolean isFunction(Class<?> c)
- Returns:
trueif the given type is a known function type,falseotherwise.
Note that only the type itself and not its type hierarchy is considered.- Throws:
NullPointerException- Ifcisnull.
-
functionOfArity
public static Class<?> functionOfArity(int arity)
- Parameters:
arity- anintcorresponding to aFunctionof that arity.- Returns:
- the
Functionof arityarity. - Throws:
IllegalArgumentException- iff there is no knownFunctionof arityarity.
-
arityOf
public static int arityOf(Class<?> c)
- Parameters:
c- theClassof unknown arity- Returns:
- the arity of
c, or-1ifcis not aFunction.
-
nary
public static <O> Functions.ArityN<O> nary(Producer<O> f)
Converts aProducerto aFunctions.ArityN.- Type Parameters:
O- the type variable linked the output of theProducer- Parameters:
f- theProducerto be converted into aFunctions.ArityN- Returns:
- a
Functions.ArityNcreated from theProducer
-
nary
public static <O> Functions.ArityN<O> nary(Function<?,O> f)
Converts aFunctionto aFunctions.ArityN.- Type Parameters:
O- the type variable linked the output of theFunction- Parameters:
f- theFunctionto be converted into aFunctions.ArityN- Returns:
- a
Functions.ArityNcreated from theFunction
-
nary
public static <O> Functions.ArityN<O> nary(BiFunction<?,?,O> f)
Converts aBiFunctionto aFunctions.ArityN.- Type Parameters:
O- the type variable linked the output of theBiFunction- Parameters:
f- theBiFunctionto be converted into aFunctions.ArityN- Returns:
- a
Functions.ArityNcreated from theBiFunction
-
nary
public static <O> Functions.ArityN<O> nary(Functions.Arity3<?,?,?,O> f)
Converts aFunctions.Arity3to aFunctions.ArityN.- Type Parameters:
O- the type variable linked the output of theFunctions.Arity3- Parameters:
f- theFunctions.Arity3to be converted into aFunctions.ArityN- Returns:
- a
Functions.ArityNcreated from theFunctions.Arity3
-
nary
public static <O> Functions.ArityN<O> nary(Functions.Arity4<?,?,?,?,O> f)
Converts aFunctions.Arity4to aFunctions.ArityN.- Type Parameters:
O- the type variable linked the output of theFunctions.Arity4- Parameters:
f- theFunctions.Arity4to be converted into aFunctions.ArityN- Returns:
- a
Functions.ArityNcreated from theFunctions.Arity4
-
nary
public static <O> Functions.ArityN<O> nary(Functions.Arity5<?,?,?,?,?,O> f)
Converts aFunctions.Arity5to aFunctions.ArityN.- Type Parameters:
O- the type variable linked the output of theFunctions.Arity5- Parameters:
f- theFunctions.Arity5to be converted into aFunctions.ArityN- Returns:
- a
Functions.ArityNcreated from theFunctions.Arity5
-
nary
public static <O> Functions.ArityN<O> nary(Functions.Arity6<?,?,?,?,?,?,O> f)
Converts aFunctions.Arity6to aFunctions.ArityN.- Type Parameters:
O- the type variable linked the output of theFunctions.Arity6- Parameters:
f- theFunctions.Arity6to be converted into aFunctions.ArityN- Returns:
- a
Functions.ArityNcreated from theFunctions.Arity6
-
nary
public static <O> Functions.ArityN<O> nary(Functions.Arity7<?,?,?,?,?,?,?,O> f)
Converts aFunctions.Arity7to aFunctions.ArityN.- Type Parameters:
O- the type variable linked the output of theFunctions.Arity7- Parameters:
f- theFunctions.Arity7to be converted into aFunctions.ArityN- Returns:
- a
Functions.ArityNcreated from theFunctions.Arity7
-
nary
public static <O> Functions.ArityN<O> nary(Functions.Arity8<?,?,?,?,?,?,?,?,O> f)
Converts aFunctions.Arity8to aFunctions.ArityN.- Type Parameters:
O- the type variable linked the output of theFunctions.Arity8- Parameters:
f- theFunctions.Arity8to be converted into aFunctions.ArityN- Returns:
- a
Functions.ArityNcreated from theFunctions.Arity8
-
nary
public static <O> Functions.ArityN<O> nary(Functions.Arity9<?,?,?,?,?,?,?,?,?,O> f)
Converts aFunctions.Arity9to aFunctions.ArityN.- Type Parameters:
O- the type variable linked the output of theFunctions.Arity9- Parameters:
f- theFunctions.Arity9to be converted into aFunctions.ArityN- Returns:
- a
Functions.ArityNcreated from theFunctions.Arity9
-
nary
public static <O> Functions.ArityN<O> nary(Functions.Arity10<?,?,?,?,?,?,?,?,?,?,O> f)
Converts aFunctions.Arity10to aFunctions.ArityN.- Type Parameters:
O- the type variable linked the output of theFunctions.Arity10- Parameters:
f- theFunctions.Arity10to be converted into aFunctions.ArityN- Returns:
- a
Functions.ArityNcreated from theFunctions.Arity10
-
nary
public static <O> Functions.ArityN<O> nary(Functions.Arity11<?,?,?,?,?,?,?,?,?,?,?,O> f)
Converts aFunctions.Arity11to aFunctions.ArityN.- Type Parameters:
O- the type variable linked the output of theFunctions.Arity11- Parameters:
f- theFunctions.Arity11to be converted into aFunctions.ArityN- Returns:
- a
Functions.ArityNcreated from theFunctions.Arity11
-
nary
public static <O> Functions.ArityN<O> nary(Functions.Arity12<?,?,?,?,?,?,?,?,?,?,?,?,O> f)
Converts aFunctions.Arity12to aFunctions.ArityN.- Type Parameters:
O- the type variable linked the output of theFunctions.Arity12- Parameters:
f- theFunctions.Arity12to be converted into aFunctions.ArityN- Returns:
- a
Functions.ArityNcreated from theFunctions.Arity12
-
nary
public static <O> Functions.ArityN<O> nary(Functions.Arity13<?,?,?,?,?,?,?,?,?,?,?,?,?,O> f)
Converts aFunctions.Arity13to aFunctions.ArityN.- Type Parameters:
O- the type variable linked the output of theFunctions.Arity13- Parameters:
f- theFunctions.Arity13to be converted into aFunctions.ArityN- Returns:
- a
Functions.ArityNcreated from theFunctions.Arity13
-
nary
public static <O> Functions.ArityN<O> nary(Functions.Arity14<?,?,?,?,?,?,?,?,?,?,?,?,?,?,O> f)
Converts aFunctions.Arity14to aFunctions.ArityN.- Type Parameters:
O- the type variable linked the output of theFunctions.Arity14- Parameters:
f- theFunctions.Arity14to be converted into aFunctions.ArityN- Returns:
- a
Functions.ArityNcreated from theFunctions.Arity14
-
nary
public static <O> Functions.ArityN<O> nary(Functions.Arity15<?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,O> f)
Converts aFunctions.Arity15to aFunctions.ArityN.- Type Parameters:
O- the type variable linked the output of theFunctions.Arity15- Parameters:
f- theFunctions.Arity15to be converted into aFunctions.ArityN- Returns:
- a
Functions.ArityNcreated from theFunctions.Arity15
-
nary
public static <O> Functions.ArityN<O> nary(Functions.Arity16<?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,O> f)
Converts aFunctions.Arity16to aFunctions.ArityN.- Type Parameters:
O- the type variable linked the output of theFunctions.Arity16- Parameters:
f- theFunctions.Arity16to be converted into aFunctions.ArityN- Returns:
- a
Functions.ArityNcreated from theFunctions.Arity16
-
-