View Source Ash.Query.Function behaviour (ash v3.4.46)

A function is a predicate with an arguments list.

For more information on being a predicate, see Ash.Filter.Predicate. Most of the complexities are there. A function must meet both behaviours.

Summary

Callbacks

The number and types of arguments supported.

Whether or not the function return nil.

Whether or not the function can be evaluated eagerly. For example, now() cannot be.

Evaluate a function when all arguments are known valid values

If true, will be allowed to evaluate nil inputs.

The name of the function

Instantiate a new function with the provided arguments

Evaluate a function when some or no arguments are known valid values

Whether or not the function is a predicate (takes a reference as the first argument, a value as the second, and returns a boolean)

Whether or not the function should be usable when parsing input.

The return type for each corresponding set of args.

Functions

Evaluate the operator with provided inputs

Attaches the appropriate suffix to refer to an ordinal number, e.g 1 -> "1st"

Types

arg()

@type arg() :: any()

Callbacks

args()

@callback args() :: [arg()] | :var_args

The number and types of arguments supported.

can_return_nil?(func)

@callback can_return_nil?(func :: map()) :: boolean()

Whether or not the function return nil.

eager_evaluate?()

@callback eager_evaluate?() :: boolean()

Whether or not the function can be evaluated eagerly. For example, now() cannot be.

evaluate(func)

@callback evaluate(func :: map()) :: :unknown | {:known, term()} | {:error, term()}

Evaluate a function when all arguments are known valid values

evaluate_nil_inputs?()

@callback evaluate_nil_inputs?() :: boolean()

If true, will be allowed to evaluate nil inputs.

If false (the default), any nil inputs will cause a nil return.

name()

@callback name() :: atom()

The name of the function

new(list)

@callback new([term()]) :: {:ok, term()} | {:error, String.t() | Exception.t()}

Instantiate a new function with the provided arguments

partial_evaluate(func)

(optional)
@callback partial_evaluate(func) :: {:ok, func} | {:error, term()} when func: map()

Evaluate a function when some or no arguments are known valid values

predicate?()

@callback predicate?() :: boolean()

Whether or not the function is a predicate (takes a reference as the first argument, a value as the second, and returns a boolean)

private?()

@callback private?() :: boolean()

Whether or not the function should be usable when parsing input.

returns()

@callback returns() ::
  [Ash.Type.t() | {Ash.Type.t(), constraints :: Keyword.t()}]
  | Ash.Type.t()
  | {Ash.Type.t(), constraints :: Keyword.t()}
  | :unknown

The return type for each corresponding set of args.

Functions

evaluate(func)

Evaluate the operator with provided inputs

new(mod, args)

ordinal(num)

Attaches the appropriate suffix to refer to an ordinal number, e.g 1 -> "1st"

try_cast_arguments(configured_args, args)