Package com.im.commons
Class Functional
- java.lang.Object
-
- com.im.commons.Functional
-
public final class Functional extends java.lang.ObjectProvides set of generally useful higher-order functions.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <F,T>
com.google.common.base.Function<F,T>constant(T value)Creates a constant function that returnsvaluefor any input.static <VAL,ACCU>
ACCUfoldl(CombiningFunction<VAL,ACCU> f, ACCU z, java.lang.Iterable<? extends VAL> xs)Version offoldlas it is known in functional programming word.static <VAL,ACCU>
ACCUfoldlNull(CombiningFunction<VAL,ACCU> f, ACCU z, java.lang.Iterable<VAL> xs)Version offoldlas it is known in functional programming word handling thenullvalues.
-
-
-
Method Detail
-
foldlNull
public static <VAL,ACCU> ACCU foldlNull(CombiningFunction<VAL,ACCU> f, ACCU z, java.lang.Iterable<VAL> xs)
Version offoldlas it is known in functional programming word handling thenullvalues.Applied to a binary operator, a starting value (typically the left-identity of the operator), and a list, reduces the list using the binary operator, from left to right:
- Type Parameters:
VAL- type of values to be foldedACCU- resulting value- Parameters:
f- reducing operatorz- starting valuexs- the list to be reduced- Returns:
- reduced result
- See Also:
foldl(com.im.commons.CombiningFunction<VAL, ACCU>, ACCU, java.lang.Iterable<? extends VAL>)
-
foldl
public static <VAL,ACCU> ACCU foldl(CombiningFunction<VAL,ACCU> f, ACCU z, java.lang.Iterable<? extends VAL> xs)
Version offoldlas it is known in functional programming word.Applied to a binary operator, a starting value (typically the left-identity of the operator), and a list, reduces the list using the binary operator, from left to right:
- Type Parameters:
VAL- type of values to be foldedACCU- resulting value- Parameters:
f- reducing operatorz- starting valuexs- the list to be reduced- Returns:
- reduced result
- See Also:
foldlNull(com.im.commons.CombiningFunction<VAL, ACCU>, ACCU, java.lang.Iterable<VAL>)
-
constant
public static <F,T> com.google.common.base.Function<F,T> constant(T value)
Creates a constant function that returnsvaluefor any input. I.e. it ignore its input parameter.This function is similar to the
Functions.constant(E)from Guava library but is generic in its input parameter which fits better in some scenarios.- Type Parameters:
F- type of input parameter (mapping from)T- type of output parameter (mapping to)- Parameters:
value- the constant value for the function to return- Returns:
- a constant function that always returns
value
-
-