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.
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
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic class -
Method Summary
Modifier and TypeMethodDescriptionstatic RiskscapeFunctionasFunction(RealizableFunction function, ArgumentList args, Type returnType) Wrap aRealizableFunctionin aRiskscapeFunction.static RiskscapeFunctioncontextOnly(ArgumentList args, Type returnType, Function<RealizationContext, UntypedFunction> constructor) Returns aRiskscapeFunctionthat isRealizableFunction, where realization is needed just so the implementation can have access to theRealizationContextstatic IdentifiedFunctionidentified(RealizableFunction function, FunctionMetadata metadata) Build an IdentifiedFunction from a RealizableFunction and some FunctionMetadata.default booleanOverride me and return false if thisRealizableFunctiondoes not want the expression realization to attempt to coerce equivalent argument types before realizing the function.realize(RealizationContext context, FunctionCall functionCall, List<Type> argumentTypes) Attempt to adapt a function call to the given types.
-
Method Details
-
contextOnly
static RiskscapeFunction contextOnly(ArgumentList args, Type returnType, Function<RealizationContext, UntypedFunction> constructor) Returns a
RiskscapeFunctionthat isRealizableFunction, where realization is needed just so the implementation can have access to theRealizationContext- Parameters:
args- the argument list to advertise and return with realizingreturnType- the return type to advertise and return with realizingconstructor- a function that builds anUntypedFunctionto 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
RealizableFunctionin aRiskscapeFunction. Saves you from the boiler plate of having to makeRealizableFunction's implement RiskscapeFunction as well. Instead, just add anasFunctionmethod to your RealizableFunction implementation that calls thisasFunctionmethod (See BaseRealizableFunction in engine)- Parameters:
function- the function to wrap up in a RiskscapeFunctionargs- the argument types to advertise - can be different to the ones the RealizableFunction returns on realizationreturnType- the return type to advertise - can be default to the one the RealizableFunction returns on realization
-
identified
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.
-
isDoTypeAdaptation
default boolean isDoTypeAdaptation()Override me and return false if this
RealizableFunctiondoes not want the expression realization to attempt to coerce equivalent argument types before realizing the function. Any function that advertises generic types, e.g. list(struct(foo: anything)) is going to want to disable this (e.g. override and return false) -
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 callargumentTypes- 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.
-