Class LambdaFunctionSet

All Implemented Interfaces:
JepComponent, Serializable

public class LambdaFunctionSet extends FunctionSet
Adds list processing and higher order functions.
  • 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 value accumulate(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 empty foldOr([a,b]=>a+b, -1, [1..5])
    • reduce - reduces a stream using a binary lambda function and an initial value reduce(1, [a,b]=>a*b, [1..5])
    • first - returns the first element of a stream first([1..5])
    • firstOr - returns the first element of a stream or a default value if the stream is empty firstOr(-1, [1..5])
    • last - returns the last element of a stream last([1..5])
    • count - counts the number of elements in a stream count([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 predicate anyMatch(x => x%2==0, [1..5])
    • allMatch - returns true if all items match a predicate allMatch(x => x%2==0, [1..5])
    • noneMatch - returns true if no items match a predicate noneMatch(x => x%2==0, [1..5])
    • firstMatchOr - finds the first matching item or a default value firstMatchOr(x => x%2==0, -1, [1..5])
  • Other functions:
    • apply - applies a lambda function to a single value apply(x=>sqrt(x), 25)
    • define - defines regular Jep function using a lambda function define(mysum, [x,y] => x+y); mysum(2,3);

Names used can be changed in the properties file

LambdaFunctionSet.map=map
Use an ! in the property value to prevent the function being added, e.g.
LambdaFunctionSet.map=! skip
Since:
Jep 4.1, extensions 2.2
See Also:
  • Constructor Details

    • LambdaFunctionSet

      public LambdaFunctionSet()
      Creates a set of higher order functions. The implementations uses Double.compareTo(Double) to compare numeric values in the nsort and rsort functions; MinMax to find the minimum and maximum numeric values in the min and max functions; and Add to sum numeric values in the sum function.
    • LambdaFunctionSet

      public LambdaFunctionSet(FieldI field)
      Creates a set of higher order functions for a specific field. The implementations uses FieldComparator in the nsort and rsort functions; ElementMinMax to find the minimum and maximum numeric values in the min and max functions; and the FieldI.add(Object, Object) method to sum numeric values in the sum function.
      Parameters:
      field - Field to use for numeric comparisons and sums.