Class StreamIterate

All Implemented Interfaces:
JepComponent, PostfixMathCommandI, Serializable

public class StreamIterate extends NaryFunction implements JepComponent
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.

This can generate finite streams

code iterate(0, x=>x+1, x=>x<10) . count()
or indefinite streams limited by operations further down the chain
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:
  • Constructor Details

    • StreamIterate

      public StreamIterate()
  • Method Details

    • eval

      public Object eval(Object[] args) throws EvaluationException
      Description copied from class: NaryFunction
      Evaluate the function
      Specified by:
      eval in class NaryFunction
      Parameters:
      args - arguments to the function
      Returns:
      value returned by the function
      Throws:
      EvaluationException - if the calculation cannot be performed
    • init

      public void init(Jep jep)
      Description copied from interface: JepComponent
      Initialize 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:
      init in interface JepComponent
      Parameters:
      jep - the current Jep instance
    • getLightWeightInstance

      public JepComponent getLightWeightInstance()
      Description copied from interface: JepComponent
      Gets a light-weight instance suitable for using in multiple threads.
      Specified by:
      getLightWeightInstance in interface JepComponent
      Returns:
      either a new instance, null or 'this'.
    • checkNumberOfParameters

      public boolean checkNumberOfParameters(int n)
      Description copied from class: PostfixMathCommand
      Checks the number of parameters of the function. Functions which set numberOfParameter=-1 should overload this method
      Specified by:
      checkNumberOfParameters in interface PostfixMathCommandI
      Overrides:
      checkNumberOfParameters in class PostfixMathCommand
      Parameters:
      n - number of parameters function will be called with.
      Returns:
      false if an illegal number of parameters is supplied, true otherwise.