Class StreamIterate
java.lang.Object
com.singularsys.jep.functions.PostfixMathCommand
com.singularsys.jep.functions.NaryFunction
com.singularsys.extensions.stream.StreamIterate
- All Implemented Interfaces:
JepComponent,PostfixMathCommandI,Serializable
Generate an infinite sequence using iteration using an
initial value and a lambda function to calculate the next value and
optionally a lambda function to determine when to end the stream.
or indefinite streams limited by operations further down the chain
This can generate finite streams
code iterate(0, x=>x+1, x=>x<10) . count()
iterate(1, x=>x*2) . limit(10) . toList()
This is implemented using the Stream.iterate(Object, UnaryOperator) and
Stream.iterate(Object, Predicate, UnaryOperator) methods of the Java Stream API.
- See Also:
-
Field Summary
Fields inherited from class com.singularsys.jep.functions.PostfixMathCommand
curNumberOfParameters, description, name, NaN, numberOfParameters -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleancheckNumberOfParameters(int n) Checks the number of parameters of the function.Evaluate the functionGets a light-weight instance suitable for using in multiple threads.voidInitialize the component.Methods inherited from class com.singularsys.jep.functions.NaryFunction
runMethods inherited from class com.singularsys.jep.functions.PostfixMathCommand
asArray, asBool, asDouble, asInt, asLong, asStrictInt, asString, asType, getDescription, getDescription, getDescriptionWithType, getName, getNumberOfParameters, setCurNumberOfParameters, setDescription, setName, toString, toString
-
Constructor Details
-
StreamIterate
public StreamIterate()
-
-
Method Details
-
eval
Description copied from class:NaryFunctionEvaluate the function- Specified by:
evalin classNaryFunction- Parameters:
args- arguments to the function- Returns:
- value returned by the function
- Throws:
EvaluationException- if the calculation cannot be performed
-
init
Description copied from interface:JepComponentInitialize the component. This method is called whenever a component is added to Jep. Hence, it allows components to keep track of the other components they may rely on.- Specified by:
initin interfaceJepComponent- Parameters:
jep- the current Jep instance
-
getLightWeightInstance
Description copied from interface:JepComponentGets a light-weight instance suitable for using in multiple threads.- Specified by:
getLightWeightInstancein interfaceJepComponent- Returns:
- either a new instance, null or 'this'.
-
checkNumberOfParameters
public boolean checkNumberOfParameters(int n) Description copied from class:PostfixMathCommandChecks the number of parameters of the function. Functions which set numberOfParameter=-1 should overload this method- Specified by:
checkNumberOfParametersin interfacePostfixMathCommandI- Overrides:
checkNumberOfParametersin classPostfixMathCommand- Parameters:
n- number of parameters function will be called with.- Returns:
- false if an illegal number of parameters is supplied, true otherwise.
-