Class FirstMatchOr

All Implemented Interfaces:
JepComponent, PostfixMathCommandI, Serializable

public class FirstMatchOr extends NaryFunction implements JepComponent
Finds the first element that matches a predicate or return a default value.
firstMatchOr(x => x%2==0, -1, [1,2,3]); // 2
firstMatchOr(x => x%2==0, -1, [1,3,5]); // -1
Using this function can be considerable faster than using
firstOr(filter(x => x%2==0, [1,2,3]), -1);
as it can stop processing the list as soon as a match is found.
Since:
Jep 4.1, extensions 2.2
See Also:
  • Constructor Details

    • FirstMatchOr

      public FirstMatchOr()
  • 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'.