# `Ash.Query.Operator`
[🔗](https://github.com/ash-project/ash/blob/v3.24.1/lib/ash/query/operator/operator.ex#L5)

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.

# `can_return_nil?`

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

Whether or not the operator can evaluate to nil.

# `evaluate`

```elixir
@callback evaluate(term()) :: term()
```

Evaluates the operator in Elixir

# `evaluate_nil_inputs?`

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

# `new`

```elixir
@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?`

```elixir
@callback predicate?() :: boolean()
```

# `returns`

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

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

The implementation of the inspect protocol.

If not defined, it will be inferred

# `types`

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

# `evaluate`

Evaluate the operator with provided inputs

# `find_overload`

Finds the matching overload for an operator based on the resolved types of its arguments.

Returns `{type_mod, overload_types}` or `nil`.

# `new`

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

# `operator_expression`

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

# `operator_overloads`

Get type overloads for the given operator

# `operator_symbols`

# `operators`

---

*Consult [api-reference.md](api-reference.md) for complete listing*
