Class StreamWhile

All Implemented Interfaces:
JepComponent, PostfixMathCommandI, Serializable

public class StreamWhile extends BinaryFunction implements JepComponent
Filter a stream so only the elements from the start of the stream that match a criteria are returned. The first element which does not match the criteria and all subsequent elements are not included in the result stream. This allows potentially infinite streams to trimmed to a stream of finite length to be returned.

For example, if primes() returns an infinite stream of prime numbers, then

code primes() . while(p=> p<100)
will return a stream of all prime numbers less than 100.

The function uses the Java Stream method Stream.takeWhile(Predicate).

See Also:
  • Constructor Details

    • StreamWhile

      public StreamWhile()
  • Method Details

    • eval

      public Object eval(Object l, Object r) throws EvaluationException
      Description copied from class: BinaryFunction
      Evaluate the function
      Specified by:
      eval in class BinaryFunction
      Parameters:
      l - lhs argument
      r - rhs argument
      Returns:
      the results
      Throws:
      EvaluationException - if the function cannot be evaluated.
    • 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'.