Class StreamFold
java.lang.Object
com.singularsys.jep.functions.PostfixMathCommand
com.singularsys.jep.functions.BinaryFunction
com.singularsys.extensions.stream.StreamFold
- All Implemented Interfaces:
ZeroLengthBehaviourI,ZeroLengthBehaviourI.DefaultZeroLengthBehaviourI,JepComponent,PostfixMathCommandI,Serializable
public class StreamFold
extends BinaryFunction
implements JepComponent, ZeroLengthBehaviourI.DefaultZeroLengthBehaviourI
Fold a list using a lambda function to reduce the list down to a single argument.
Sum = [x,y]=>x+y fold(Sum, [1,2,3,4,5])If the stream has a single element, then that element is returned without applying the lambda function.
By default, if the stream is empty, an exception is thrown,
but the behaviour can be configured using the methods of the ZeroLengthBehaviourI interface.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class com.singularsys.jep.functions.BinaryFunction
BinaryFunction.BiFunctionWithException<T>Nested classes/interfaces inherited from interface com.singularsys.jep.functions.ZeroLengthBehaviourI
ZeroLengthBehaviourI.DefaultZeroLengthBehaviourI, ZeroLengthBehaviourI.ZeroLengthErrorBehaviour, ZeroLengthBehaviourI.ZeroLengthHelper -
Field Summary
Fields inherited from class com.singularsys.jep.functions.PostfixMathCommand
curNumberOfParameters, description, name, NaN, numberOfParameters -
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor with no zero length array handling, i.e. an exception is thrown when a zero length array is passed as an argument. -
Method Summary
Modifier and TypeMethodDescriptionEvaluate the functionGets a light-weight instance suitable for using in multiple threads.Gets the helper class which implements the zero length behaviour.voidInitialize the component.Methods inherited from class com.singularsys.jep.functions.BinaryFunction
instanceOf, instanceOf, instanceOf, instanceOf, runMethods inherited from class com.singularsys.jep.functions.PostfixMathCommand
asArray, asBool, asDouble, asInt, asLong, asStrictInt, asString, asType, checkNumberOfParameters, getDescription, getDescription, getDescriptionWithType, getName, getNumberOfParameters, setCurNumberOfParameters, setDescription, setName, toString, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface com.singularsys.jep.functions.ZeroLengthBehaviourI
getErrorMessage, getValueOrException, zeroLengthResultOrExceptionMethods inherited from interface com.singularsys.jep.functions.ZeroLengthBehaviourI.DefaultZeroLengthBehaviourI
getZeroLengthErrorBehaviour, getZeroLengthValue, setZeroLengthErrorBehaviour, setZeroLengthValue
-
Constructor Details
-
StreamFold
public StreamFold()Default constructor with no zero length array handling, i.e. an exception is thrown when a zero length array is passed as an argument.
-
-
Method Details
-
eval
Description copied from class:BinaryFunctionEvaluate the function- Specified by:
evalin classBinaryFunction- Parameters:
l- lhs argumentr- rhs argument- Returns:
- the results
- Throws:
EvaluationException- if the function cannot be evaluated.
-
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'.
-
getZeroLengthHelper
Description copied from interface:ZeroLengthBehaviourI.DefaultZeroLengthBehaviourIGets the helper class which implements the zero length behaviour. The standard implementation is:ZeroLengthHelper zeroLengthHelper = new ZeroLengthHelper(); @Override public ZeroLengthBehaviourI getZeroLengthHelper() { return zeroLengthHelper; }- Specified by:
getZeroLengthHelperin interfaceZeroLengthBehaviourI.DefaultZeroLengthBehaviourI- Returns:
- the helper class
-