Interface RealizableFunction

All Known Implementing Classes:
AggregationFunctionAdapter
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 RealizableFunction

An interface for functions to indicate that they can be realized for a particular set of input arguments in a riskscape language expression. Useful for functions that want to allow more flexible type computation than the default behaviour provided to all functions

  • Method Details

    • contextOnly

      static RiskscapeFunction contextOnly(ArgumentList args, Type returnType, Function<RealizationContext,UntypedFunction> constructor)

      Returns a RiskscapeFunction that is RealizableFunction, where realization is needed just so the implementation can have access to the RealizationContext

      Parameters:
      args - the argument list to advertise and return with realizing
      returnType - the return type to advertise and return with realizing
      constructor - a function that builds an UntypedFunction to use for the implementation, supplying the realization context for use during execution.
      Returns:
      a function that returns a wrapped up version of the given function when RiskscapeFunction.getRealizable() is called
    • asFunction

      static RiskscapeFunction asFunction(RealizableFunction function, ArgumentList args, Type returnType)

      Wrap a RealizableFunction in a RiskscapeFunction. Saves you from the boiler plate of having to make RealizableFunction's implement RiskscapeFunction as well. Instead, just add an asFunction method to your RealizableFunction implementation that calls this asFunction method (See BaseRealizableFunction in engine)

      Parameters:
      function - the function to wrap up in a RiskscapeFunction
      args - the argument types to advertise - can be different to the ones the RealizableFunction returns on realization
      returnType - the return type to advertise - can be default to the one the RealizableFunction returns on realization
    • identified

      static IdentifiedFunction identified(RealizableFunction function, FunctionMetadata metadata)

      Build an IdentifiedFunction from a RealizableFunction and some FunctionMetadata. Serves as an alternative to extending BaseRealizableFunction (in engine), which isn't always going to be appropriate.

    • realize

      ResultOrProblems<RiskscapeFunction> realize(RealizationContext context, FunctionCall functionCall, List<Type> argumentTypes)

      Attempt to adapt a function call to the given types. This can also be used to do constant optimizations etc or anything else.

      Parameters:
      functionCall - the part of the abstract syntax tree for the function call
      argumentTypes - the types of the arguments that have been supplied to the function
      Returns:
      the adapted function, or some problems if it couldn't be adapted.