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

public interface RiskscapeFunction extends UntypedFunction, AutoCloseable

General interface for any kind of function that accepts and returns riskscape types values.

  • Field Details

    • LOG

      static final org.slf4j.Logger LOG
    • BUILT_IN

      static final URI 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 an UntypedFunction to make it fulfill the RiskscapeFunction 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 any RealizedExpressions 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 source
      function - a function we are extending with type metadata.
      closeThese - any AutoCloseable 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

      List<Type> getArgumentTypes()
      Returns:
      the types that this function expects
    • getReturnType

      Type getReturnType()
      Returns:
      the type that this function should return
    • validate

      default ResultOrProblems<Boolean> validate(RealizationContext context)

      Validate that the function can be run.

      To be considered valid there should be no Problems 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

      default Optional<RealizableFunction> getRealizable()
      Returns:
      a RealizableFunction that can realize this RiskscapeFunction against a type, or empty if this function does not support realization.
    • getOverloaded

      default Optional<OverloadedFunction> getOverloaded()
      Returns:
      an OverloadedFunction that offers alternative input types for use within an expression, or empty if this function does not support overloading
    • getAggregationFunction

      default Optional<AggregationFunction> getAggregationFunction()
      Returns:
      An AggregationFunction that is functionally the same operation as this, but works with a RealizedAggregateExpression, rather than against a RealizedExpression with an RSList.
    • getArguments

      default ArgumentList getArguments()
    • getTypesFromArguments

      default List<Type> getTypesFromArguments()
    • setProblemReporter

      default void setProblemReporter(Consumer<Problem> problemReporter)

      Set a problem report that this function may use to issue Problems to if any are encountered whilst the function is being called.

      Any Problems 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

      default IdentifiedFunction builtin(String id, IdentifiedFunction.Category category)
      Returns:
      an IdentifiedFunction that wraps this function with the given metadata
    • identified

      default IdentifiedFunction identified(String id)
      Returns:
      alternative to #identified(String, String, String, IdentifiedFunction.Category) that is suitable for test cases
    • isA

      default <T extends RiskscapeFunction> Optional<T> isA(Class<T> type)
    • close

      default void close()
      Specified by:
      close in interface AutoCloseable