Class LambdaFunctionSet
java.lang.Object
com.singularsys.jep.misc.OneShotComponent
com.singularsys.jep.misc.FunctionSet
com.singularsys.extensions.lambda.LambdaFunctionSet
- All Implemented Interfaces:
JepComponent,Serializable
Adds list processing and higher order 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.count(iterate(0, x=>x+1, x=>x<10))
- Intermediate functions:
map- maps a stream using a lambda function:map(x=>x*x, [1..5])filter- filters a stream using a lambda function a predicate:filter(x=>x%2==0, [1..10])sort- sorts a stream by a lambda function:sort([a,b]=>a>b, [3,1,4,2])dsort- sorts a stream by numeric value:dsort([3,1,4,2])rsort- sorts a stream by reverse numeric value:rsort([3,1,4,2])limit- limits a stream to a number of elements:limit(10, [1..100])skip- skips a number of elements in a stream:skip(90, [1..100])while- takes elements from a stream while a predicate is true:while(x=>x<10, [1..100])append- concatenates two streams together:append([1..5],[6..10])merge- merge two streams together pairwise using a lambda function to define how to merge elements:merge([a,b]=>a+b, [1..5], [6..10])distinct- return a list with duplicate elements removed:distinct([1,2,3,2,1])produces[1,2,3]order is not guaranteed.flatten- flatten a list of lists to a single list.flatten([[1,2],[3,4]])produces[1,2,3,4].accumulate- map a sequence using an acumulator with the previous result. Defined using and initial value and binary lambda function initial valueaccumulate(1, [prev,cur]=>prev+cur, [1..5])
- Terminal functions:
fold- folds a stream using a binary lambda function:fold([a,b]=>a+b, [1..5])foldOr- folds a stream using a binary lambda function, returning a default value if the stream is emptyfoldOr([a,b]=>a+b, -1, [1..5])reduce- reduces a stream using a binary lambda function and an initial valuereduce(1, [a,b]=>a*b, [1..5])first- returns the first element of a streamfirst([1..5])firstOr- returns the first element of a stream or a default value if the stream is emptyfirstOr(-1, [1..5])last- returns the last element of a streamlast([1..5])count- counts the number of elements in a streamcount([1..5])min- finds the minimum numeric value of a stream:min([1..5])max- finds the maximum numeric value of a stream:max([1..5])anyMatch- returns true if any item match a predicateanyMatch(x => x%2==0, [1..5])allMatch- returns true if all items match a predicateallMatch(x => x%2==0, [1..5])noneMatch- returns true if no items match a predicatenoneMatch(x => x%2==0, [1..5])firstMatchOr- finds the first matching item or a default valuefirstMatchOr(x => x%2==0, -1, [1..5])
- Other functions:
apply- applies a lambda function to a single valueapply(x=>sqrt(x), 25)define- defines regular Jep function using a lambda functiondefine(mysum, [x,y] => x+y); mysum(2,3);
Names used can be changed in the properties file
LambdaFunctionSet.map=map
LambdaFunctionSet.map=! skip
- Since:
- Jep 4.1, extensions 2.2
- See Also:
-
Field Summary
Fields inherited from class com.singularsys.jep.misc.FunctionSet
functions -
Constructor Summary
ConstructorsConstructorDescriptionCreates a set of higher order functions.LambdaFunctionSet(FieldI field) Creates a set of 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
-
LambdaFunctionSet
public LambdaFunctionSet()Creates a set of 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. -
LambdaFunctionSet
Creates a set of 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.
-