Class StreamDistinct

All Implemented Interfaces:
JepComponent, PostfixMathCommandI, Serializable

public class StreamDistinct extends UnaryFunction implements JepComponent
Return only distinct elements of a stream.
 [1,2,3,2,1] . distinct()
returns [1,2,3].

Uses the Stream.distinct() methods. Note this uses Object.equals(Object) to compare elements. Hence [-0.0,0.0].distinct() will return a stream with two elements. To ensure that -0.0 and 0.0 are treated as the same element, use a map to transform the stream before applying distinct, for example: [-0.0, +0.0] . map(x=> x==0 ? 0 : x) . distinct()

Since:
Jep 4.1
See Also:
  • Constructor Details

    • StreamDistinct

      public StreamDistinct()
  • Method Details

    • eval

      public Object eval(Object l) throws EvaluationException
      Description copied from class: UnaryFunction
      Evaluate the function
      Specified by:
      eval in class UnaryFunction
      Parameters:
      l - the single argument passed in
      Returns:
      the result of the function
      Throws:
      EvaluationException - on error
    • 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'.