Interface Function<T>

All Superinterfaces:
Value
All Known Implementing Classes:
JavaFunction
Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface Function<T> extends Value
Represents a Molang function. Receives a certain amount of parameters and (optionally) returns a value. Can be called from Molang code using call expressions: my_function(1, 2, 3)

This is a very low-level function that is "expression-sensitive", this means, it takes the raw expression arguments instead of the evaluated expression argument values.

Since:
3.0.0
  • Method Details

    • evaluate

      @Nullable @Nullable Value evaluate(@NotNull @NotNull ExecutionContext<T> context, @NotNull @NotNull Function.Arguments arguments)
      Executes this function with the given arguments.
      Parameters:
      context - The execution context
      arguments - The arguments
      Returns:
      The function result
      Since:
      3.0.0
    • evaluate

      @Nullable default @Nullable Value evaluate(@NotNull @NotNull ExecutionContext<T> context)
      Executes this function.
      Parameters:
      context - The execution context
      Returns:
      The function result
      Since:
      3.0.0
    • pure

      default boolean pure()
      Determines if this function is pure or not.

      A pure function is a function that has the following properties:

      1. The function return values are identical for identical arguments, and
      2. The function has no side effects

      The compiler or interpreter may pre-evaluate these functions ahead of time. In case of compiling, the function may be called during compile time, to use the function's result instead.

      Returns:
      If this function is pure or not.
      Since:
      3.0.0