Search documentation of ash

# View Source Ash.Query.Operator behaviour (ash v3.4.30)

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

can_return_nil?(func)

Whether or not the operator can evaluate to nil.

evaluate(term)

Evaluates the operator in Elixir

evaluate_nil_inputs?()

If `true`, will be allowed to evaluate `nil` inputs.

new(term, term)

Create a new predicate. There are various return types possible

predicate?()
returns()

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

to_string(struct, t)

The implementation of the inspect protocol.

types()

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()

# Callbacks

Link to this callback

# can_return_nil?(func)

View Source

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

Whether or not the operator can evaluate to nil.

Link to this callback

# evaluate(term)

View Source

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

Evaluates the operator in Elixir

Link to this callback

# evaluate_nil_inputs?()

View Source

    @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.

Link to this callback

# new(term, term)

View Source

    @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

Link to this callback

# predicate?()

View Source

    @callback predicate?() :: boolean()

Link to this callback

# returns()

View Source

    @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`.

Link to this callback

# to_string(struct, t)

View Source

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

The implementation of the inspect protocol.

If not defined, it will be inferred

Link to this callback

# types()

View Source

    @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

Link to this function

# evaluate(op)

View Source

Evaluate the operator with provided inputs

Link to this function

# new(mod, left, right)

View Source

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

Link to this function

# operator_overloads(operator)

View Source

Get type overloads for the given operator

Link to this function

# operator_symbols()

View Source
Link to this function

# operators()

View Source