All Implemented Interfaces:
FromSourceLocation, ToNode, TypeCheck, ToCondition, ToExpression

public final class Coalesce extends LibraryFunction
A coalesce function that returns the first non-empty value.

This variadic function requires two or more arguments. At runtime, returns the first argument that contains a non-EmptyValue, otherwise returns the result of the last argument.

Type checking rules:

  • coalesce(T, T, T) => T (same types)
  • coalesce(Optional<T>, T, T) => T (any non-optional makes result non-optional)
  • coalesce(Optional<T>, Optional<T>, Optional<T>) => Optional<T> (all optional)

Available since: rules engine 1.1.

  • Field Details

  • Method Details

    • getDefinition

      public static Coalesce.Definition getDefinition()
      Gets the FunctionDefinition implementation.
      Returns:
      the function definition.
    • ofExpressions

      public static Coalesce ofExpressions(ToExpression... args)
      Creates a Coalesce function from variadic expressions.
      Parameters:
      args - the expressions to coalesce
      Returns:
      The resulting Coalesce function.
    • ofExpressions

      public static Coalesce ofExpressions(List<? extends ToExpression> args)
      Creates a Coalesce function from a list of expressions.
      Parameters:
      args - the expressions to coalesce
      Returns:
      The resulting Coalesce function.
    • availableSince

      public RulesVersion availableSince()
      Description copied from class: SyntaxElement
      Get the rules engine version that this syntax element is available since.
      Overrides:
      availableSince in class SyntaxElement
      Returns:
      the version this is available since.
    • accept

      public <R> R accept(ExpressionVisitor<R> visitor)
      Description copied from class: Expression
      Invoke the ExpressionVisitor functions for this expression.
      Specified by:
      accept in class Expression
      Type Parameters:
      R - the visitor return type.
      Parameters:
      visitor - the visitor to be invoked.
      Returns:
      the return value of the visitor.
    • typeCheck

      public Type typeCheck(Scope<Type> scope)
      Description copied from interface: TypeCheck
      Checks whether the given types within a scope satisfy the constraints.
      Specified by:
      typeCheck in interface TypeCheck
      Overrides:
      typeCheck in class Expression
      Parameters:
      scope - the scope to evaluate.
      Returns:
      the type validated by the scope check.