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
Modifier and TypeInterfaceDescriptionstatic class
-
Method Summary
Modifier and TypeMethodDescriptionstatic RiskscapeFunction
asFunction
(RealizableFunction function, ArgumentList args, Type returnType) Wrap aRealizableFunction
in aRiskscapeFunction
.static RiskscapeFunction
contextOnly
(ArgumentList args, Type returnType, Function<RealizationContext, UntypedFunction> constructor) Returns aRiskscapeFunction
that isRealizableFunction
, where realization is needed just so the implementation can have access to theRealizationContext
static IdentifiedFunction
identified
(RealizableFunction function, FunctionMetadata metadata) Build an IdentifiedFunction from a RealizableFunction and some FunctionMetadata.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
RiskscapeFunction
that 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 anUntypedFunction
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 aRiskscapeFunction
. Saves you from the boiler plate of having to makeRealizableFunction
's implement RiskscapeFunction as well. Instead, just add anasFunction
method to your RealizableFunction implementation that calls thisasFunction
method (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.
-
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.
-