Interface RiskscapeFunction
- All Superinterfaces:
AutoCloseable
,UntypedFunction
- All Known Subinterfaces:
IdentifiedFunction
- All Known Implementing Classes:
AddAggregationFunction
,AggregationFunctionAdapter
,BinaryFunction
,BinaryOperatorFunction
,BinaryPredicateFunction
,ConstantFunction
,IdentifiedFunction.Wrapping
,JavaFunction
,MetadataBasedFunction
,NullSafeFunction
,RealizableFunction.MetadataIdentifiedRealizableFunction
,UnaryFunction
General interface for any kind of function that accepts and returns riskscape types values.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptiondefault IdentifiedFunction
builtin
(String id, IdentifiedFunction.Category category) default void
close()
static RiskscapeFunction
create
(Object source, List<Type> argumentTypes, Type returnType, UntypedFunction function, AutoCloseable... closeThese) Create aRiskscapeFunction
from the given types and untyped function.default Optional<AggregationFunction>
default ArgumentList
default Optional<OverloadedFunction>
default Optional<RealizableFunction>
default IdentifiedFunction
identified
(String id) default IdentifiedFunction
identified
(String id, String description, URI source, IdentifiedFunction.Category category) default <T extends RiskscapeFunction>
Optional<T>default void
setProblemReporter
(Consumer<Problem> problemReporter) Set a problem report that this function may use to issueProblem
s to if any are encountered whilst the function is being called.default ResultOrProblems<Boolean>
validate
(RealizationContext context) Validate that the function can be run.Methods inherited from interface nz.org.riskscape.engine.function.UntypedFunction
call
-
Field Details
-
LOG
static final org.slf4j.Logger LOG -
BUILT_IN
-
-
Method Details
-
create
static RiskscapeFunction create(Object source, List<Type> argumentTypes, Type returnType, UntypedFunction function, AutoCloseable... closeThese) Create a
RiskscapeFunction
from the given types and untyped function. Note that this won't add any type checking or coercion around the function call, it simply serves as a way to add the type metadata to anUntypedFunction
to make it fulfill theRiskscapeFunction
interface.Also accepts an optional list of
AutoCloseable
objects to clean up when the function gets closed. It's worthy of note that there is no standard mechanism for cleaning up resources allocated to functions that realize lambda expressions - the closing of anyRealizedExpression
s or related objects must be done by the function when it's closed. If a lambda scope or function is passed around as data in a tuple, then there is no standard way to clean up resources attached to it (see https://gitlab.catalyst.net.nz/riskscape/riskscape/-/issues/1441 as an example of this.- Parameters:
source
- an object to use in the toString of this function to track where it came from, or null to just use the function as the sourcefunction
- a function we are extending with type metadata.closeThese
- anyAutoCloseable
resources to clean up when this function is closed. Can pass nulls, they will be skipped/ignored- Returns:
- a RiskscapeFunction that can be used as part of a RiskScape expression
-
getArgumentTypes
- Returns:
- the types that this function expects
-
getReturnType
Type getReturnType()- Returns:
- the type that this function should return
-
validate
Validate that the function can be run.
To be considered valid there should be no
Problem
s found that are at error or fatal. Finding problems of lower severity should not make a function invalid.- Returns:
- ResultOrProblems indicating if function is valid
-
getRealizable
- Returns:
- a
RealizableFunction
that can realize thisRiskscapeFunction
against a type, or empty if this function does not support realization.
-
getOverloaded
- Returns:
- an
OverloadedFunction
that offers alternative input types for use within an expression, or empty if this function does not support overloading
-
getAggregationFunction
- Returns:
- An
AggregationFunction
that is functionally the same operation as this, but works with aRealizedAggregateExpression
, rather than against aRealizedExpression
with anRSList
.
-
getArguments
-
getTypesFromArguments
-
setProblemReporter
Set a problem report that this function may use to issue
Problem
s to if any are encountered whilst the function is being called.Any
Problem
s sent to the problemReporter should clearly state what function they came from.- Parameters:
problemReporter
-
-
identified
default IdentifiedFunction identified(String id, String description, URI source, IdentifiedFunction.Category category) - Returns:
- an
IdentifiedFunction
that wraps this function with the given metadata. Note that for built-in functions,builtin(String, IdentifiedFunction.Category)
is probably a better choice to use (i.e. is simpler and encourages i18n description).
-
builtin
- Returns:
- an
IdentifiedFunction
that wraps this function with the given metadata
-
identified
- Returns:
- alternative to
#identified(String, String, String, IdentifiedFunction.Category)
that is suitable for test cases
-
isA
-
close
default void close()- Specified by:
close
in interfaceAutoCloseable
-