View Source Ash.Query.Operator behaviour (ash v3.4.43)

An operator is a predicate with a left and a right

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

Summary

Callbacks

Whether or not the operator can evaluate to nil.

Evaluates the operator in Elixir

If true, will be allowed to evaluate nil inputs.

Create a new predicate. There are various return types possible

The types that the expression can return. Should be one entry in the list for each entry in types.

The implementation of the inspect protocol.

The types accepted by the operator. Defaults to [:same, :any], which is any values of the same type.

Functions

Evaluate the operator with provided inputs

Create a new operator. Pass the module and the left and right values

Get type overloads for the given operator

Callbacks

can_return_nil?(func)

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

Whether or not the operator can evaluate to nil.

evaluate(term)

@callback evaluate(term()) :: term()

Evaluates the operator in Elixir

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.

new(term, term)

@callback new(term(), term()) ::
  {:ok, term(), term()} | {:ok, term()} | {:known, boolean()} | {:error, term()}

Create a new predicate. There are various return types possible:

  • {:ok, left, right} - Return the left/right values of the operator
  • {:ok, operator} - Return the operator itself, this or the one above are acceptable
  • {:known, boolean} - If the value is already known, e.g 1 == 1
  • {:error, error} - If there was an error creating the operator

predicate?()

@callback predicate?() :: boolean()

returns()

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

The types that the expression can return. Should be one entry in the list for each entry in types.

to_string(struct, t)

@callback to_string(
  struct(),
  Inspect.Opts.t()
) :: term()

The implementation of the inspect protocol.

If not defined, it will be inferred

types()

@callback types() :: [
  :any | :same | [Ash.Type.t() | {Ash.Type.t(), constraints :: Keyword.t()}]
]

The types accepted by the operator. Defaults to [:same, :any], which is any values of the same type.

Functions

evaluate(op)

Evaluate the operator with provided inputs

new(mod, left, right)

Create a new operator. Pass the module and the left and right values

operator_overloads(operator)

Get type overloads for the given operator

operator_symbols()

operators()