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
Finds the matching overload for an operator based on the resolved types of its arguments.
Create a new operator. Pass the module and the left and right values
Finds a custom expression module for an overloaded operator, if one exists.
Get type overloads for the given operator
Callbacks
Whether or not the operator can evaluate to nil.
Evaluates the operator in Elixir
@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.
@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.g1 == 1{:error, error}- If there was an error creating the operator
@callback predicate?() :: boolean()
@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.
@callback to_string( struct(), Inspect.Opts.t() ) :: term()
The implementation of the inspect protocol.
If not defined, it will be inferred
@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 the operator with provided inputs
Finds the matching overload for an operator based on the resolved types of its arguments.
Returns {type_mod, overload_types} or nil.
Create a new operator. Pass the module and the left and right values
Finds a custom expression module for an overloaded operator, if one exists.
Checks all known types that define operator_overloads/0 for the given operator,
and if any matching type also defines operator_expression/1, calls it with the
operator struct. Returns {:ok, custom_expression_module} or :unknown.
Get type overloads for the given operator