Package com.singularsys.jep.functions

# Class NullaryFunction

java.lang.Object
com.singularsys.jep.functions.PostfixMathCommand
com.singularsys.jep.functions.NullaryFunction

All Implemented Interfaces:
  `PostfixMathCommandI`, `Serializable`

Direct Known Subclasses:
  `ConstantFunction`, `JepTest.MyNullary`, `Random`, `ThreadSafeRandom`

public abstract class NullaryFunction extends PostfixMathCommand
Convenient base class for zero-argument nullary functions, like `random()`. Defines an `Object eval()` method for calculating the result.

Since:
  3.5
See Also:
  - Serialized Form

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `static interface`
  `NullaryFunction.SupplierWithException<T>`
  FunctionalInterface for the `BinaryFunction.instanceOf(Class, BiFunctionWithException)` method.

- ## Field Summary

  ### Fields inherited from class com.singularsys.jep.functions.PostfixMathCommand

  `curNumberOfParameters, description, name, NaN, numberOfParameters`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `NullaryFunction()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `abstract Object`
  `eval()`
  Evaluate the function
  `static NullaryFunction`
  `instanceOf(NullaryFunction.SupplierWithException<Object> fun)`
  Create a NullaryFunction from a lambda expression.
  `static NullaryFunction`
  `instanceOf(NullaryFunction.SupplierWithException<Object> fun, String name)`
  Create a NullaryFunction from a lambda expression.
  `void`
  `run(Stack<Object> stack)`
  Calls `eval()`

  ### Methods 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, toString`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- ## Constructor Details

  - ### NullaryFunction

    public NullaryFunction()

- ## Method Details

  - ### run

    public void run(Stack<Object> stack) throws EvaluationException
    Calls `eval()`
    Specified by:
      `run` in interface `PostfixMathCommandI`
    Overrides:
      `run` in class `PostfixMathCommand`
    Parameters:
      `stack` - arguments for function
    Throws:
      `EvaluationException` - if function cannot be evaluated

  - ### eval

    public abstract Object eval() throws EvaluationException
    Evaluate the function
    Returns:
      value of the function
    Throws:
      `EvaluationException` - if some error at evaluation time

  - ### instanceOf

    public static NullaryFunction instanceOf(NullaryFunction.SupplierWithException<Object> fun)
    Create a NullaryFunction from a lambda expression. For example `NullaryFunction.instanceOf(() -> Math.sqrt(2.0)`
    Parameters:
      `fun` - the lambda function
    Returns:
      a new NullaryFunction instance
    Since:
      Jep 4.0

  - ### instanceOf

    public static NullaryFunction instanceOf(NullaryFunction.SupplierWithException<Object> fun, String name)
    Create a NullaryFunction from a lambda expression. For example `NullaryFunction.instanceOf(() -> Math.sqrt(2.0)`
    Parameters:
      `fun` - the lambda function
      `name` - the name of the function
    Returns:
      a new NullaryFunction instance
    Since:
      Jep 4.0