# LibTmux.Filter.to_predicate/2

- **Module:** LibTmux
- **Package:** libtmux
- **Language:** Elixir
- **Kind:** function
- **Source:** https://github.com/libtmux/libtmux-elixir/blob/5bacf40788b43a5af27bb3656e727a921ba2db40/lib/libtmux/filter.ex#L111
- **Page:** https://libtmux.org/en/elixir/pr-173/reference/libtmux-filter-to_predicate-2/

```
to_predicate(filter, options)
@spec to_predicate(t(), [
        {:snapshot, LibTmux.Snapshot.t()}
      ]) :: (LibTmux.Schema.observation() ->
               boolean())
```

Prepares a local unary predicate after validating captured coverage, including empty domains.

Relationship and count predicates require each input to equal the
observation stored under its ID in `snapshot`. A missing or different
observation raises `LibTmux.Error` with kind `:observation_mismatch`.
Related values always come from the prepared snapshot; equal inputs from
another capture are accepted.

Scalar-only predicates read the supplied observation and may be reused
across captures. Each referenced field must be loaded: `:unloaded` raises
`:field_not_loaded` and `:unavailable` raises `:field_unavailable` before
Boolean evaluation. Known nullable values keep their comparison semantics;
unreferenced fields need not be loaded. The snapshot validates coverage
when preparing the predicate.

See the [worked example](api-examples.html#local-graph-and-filtering).

## Parameters

- `filter` (`t()`)
- `options` (`[{:snapshot, LibTmux.Snapshot.t()}]`)

## Guides

Pages that discuss `to_predicate/2`.

- [Filter captured values](/en/elixir/pr-173/guides/filtering/)
