Class ChainedFunctionSet
java.lang.Object
com.singularsys.jep.misc.OneShotComponent
com.singularsys.jep.misc.FunctionSet
com.singularsys.extensions.chained.ChainedFunctionSet
- All Implemented Interfaces:
JepComponent,Serializable
Adds chained list processing functions.
Use an ! in the property value to prevent the function being added, e.g.
- Generators:
iterate- creates a stream using an initial value, a unary lambda function giving the next value and a predicate lambda function to determine when to end the stream.iterate(0, x=>x+1, x=>x<10) . count()
- Intermediate functions:
map- maps a stream using a lambda function:[1..5] . map(x=>x*x)filter- filters a stream using a lambda function a predicate:[1..10] . filter(x=>x%2==0)sort- sorts a stream by a lambda function:[3,1,4,2] . sort((a,b)=>a>b)dsort- sorts a stream by numeric value:[3,1,4,2] . dsort()rsort- sorts a stream by reverse numeric value:[3,1,4,2] . rsort()limit- limits a stream to a number of elements:[1..100] . limit(10)skip- skips a number of elements in a stream:[1..100] . skip(90)while- takes elements from a stream while a predicate is true:[1..100] . while(x=>x<10)append- concatenates two streams together:[1..5] . append([6..10])merge- merge two streams together pairwise using a lambda function to define how to merge elements:[1..5] . merge((a,b)=>a+b, [6..10] )distinct- return a list with duplicate elements removed:[1,2,3,2,1] . distinct()produces[1,2,3]order is not guaranteed.flatten- flatten a list of lists to a single list.[[1,2],[3,4]] . flatten()produces[1,2,3,4].accumulate- accumulate value of sequence, returning a stream of intermediate values:[1..5] . accumulate(0,[tot,val]=>tot+val)produces[1,3,6,10,15]
- Terminal functions:
fold- folds a stream using a binary lambda function:[1..5]. fold((a,b)=>a+b)foldOr- folds a stream using a binary lambda function, returning a default value if the stream is empty[1..5] . foldOr((a,b)=>a+b, -1)reduce- reduces a stream using a binary lambda function and an initial value[1..5] . reduce(1, (a,b)=>a*b)first- returns the first element of a stream[1..5] . first()firstOr- returns the first element of a stream or a default value if the stream is empty[1..5] . firstOr(-1)last- returns the last element of a stream[1..5] . last()count- counts the number of elements in a stream[1..5] . count()min- finds the minimum numeric value of a stream:[1..5] . min()max- finds the maximum numeric value of a stream:[1..5] . max()anyMatch- returns true if any item match a predicate[1..5] . anyMatch(x => x%2==0)allMatch- returns true if all items match a predicate[1..5] . allMatch(x => x%2==0)noneMatch- returns true if no items match a predicate[1..5] . noneMatch(x => x%2==0)firstMatchOr- finds the first matching item or a default value[1..5] . firstMatchOr(x => x%2==0, -1)
- Other functions:
apply- applies a lambda function to a single value[1..10] . map(x=>x^2) . fold([x,y]=>x+y) . apply(x=>sqrt(x))chained- applies a lambda function taking multiple values to a sequence[1..5] . chained([n,seq]=>seq.map(x=>x^n), 3)define- defines regular Jep function using a lambda functiondefine(mysum, [x,y] => x+y); mysum(2,3);
Unlike ChainableFunctionSet These functions can only be used in a chain.
Names used can be changed in the properties file
ChainedFunctionSet.map=map
ChainedFunctionSet.map=! skip
- See Also:
-
Field Summary
Fields inherited from class com.singularsys.jep.misc.FunctionSet
functions -
Constructor Summary
ConstructorsConstructorDescriptionCreates a set of chained higher order functions.ChainedFunctionSet(FieldI field) Creates a set of chained higher order functions for a specific field. -
Method Summary
Methods inherited from class com.singularsys.jep.misc.FunctionSet
firstInit, put, putIfSetMethods inherited from class com.singularsys.jep.misc.OneShotComponent
getLightWeightInstance, init
-
Constructor Details
-
ChainedFunctionSet
public ChainedFunctionSet()Creates a set of chained higher order functions. The implementations usesDouble.compareTo(Double)to compare numeric values in thensortandrsortfunctions;MinMaxto find the minimum and maximum numeric values in theminandmaxfunctions; andAddto sum numeric values in thesumfunction. -
ChainedFunctionSet
Creates a set of chained higher order functions for a specific field. The implementations usesFieldComparatorin thensortandrsortfunctions;ElementMinMaxto find the minimum and maximum numeric values in theminandmaxfunctions; and theFieldI.add(Object, Object)method to sum numeric values in thesumfunction.- Parameters:
field- Field to use for numeric comparisons and sums.
-
-
Method Details
-
common
protected void common()
-