# `LibTmux.Selection`
[🔗](https://github.com/libtmux/libtmux-elixir/blob/b72452c198917433229bdc266a68c163541b6127/lib/libtmux/selection.ex#L1)

An ordered, materialized Enumerable over one captured entity type.

Enumeration never refreshes or performs I/O. `where/2` accepts predicate
data; `filter/2` accepts unary Elixir functions with Enum truthiness.
Holding a selection retains its snapshot graph. `Enum.to_list/1` projects
ordinary values when graph context is no longer needed.

# `t`

```elixir
@type t() :: t(LibTmux.Schema.observation())
```

A selection without a concrete observation type; use `t:t/1` to preserve item types.

# `t`

```elixir
@opaque t(item)
```

An ordered selection retaining items of one observation type and their originating snapshot.

# `count`

```elixir
@spec count(t(), LibTmux.Filter.input()) :: non_neg_integer()
```

Counts observed matching items; use size/1 for cached unfiltered size.

# `exists?`

```elixir
@spec exists?(t(), LibTmux.Filter.input()) :: boolean()
```

Returns true on the first matching observed item.

# `filter`

```elixir
@spec filter(t(item), (item -&gt; as_boolean(term()))) :: t(item)
when item: LibTmux.Schema.observation()
```

Filters with a unary local function; normal predicate exceptions propagate.

# `member_id?`

```elixir
@spec member_id?(t(), LibTmux.Ref.id()) :: boolean()
```

Checks native identity separately from Enumerable element membership.

# `new`

```elixir
@spec new(LibTmux.Snapshot.t(), :session | LibTmux.Session) :: t(LibTmux.Session.t())
@spec new(LibTmux.Snapshot.t(), :window | LibTmux.Window) :: t(LibTmux.Window.t())
@spec new(LibTmux.Snapshot.t(), :pane | LibTmux.Pane) :: t(LibTmux.Pane.t())
@spec new(LibTmux.Snapshot.t(), :window_link | LibTmux.WindowLink) ::
  t(LibTmux.WindowLink.t())
@spec new(LibTmux.Snapshot.t(), :client | LibTmux.Client) :: t(LibTmux.Client.t())
```

Materializes the observed items of an entity without I/O.

# `one`

```elixir
@spec one(t(item), LibTmux.Filter.input()) ::
  {:ok, item} | {:error, LibTmux.Error.t()}
when item: LibTmux.Schema.observation()
```

Returns exactly one match, or a structured cardinality error; stops at the second match.

# `one!`

```elixir
@spec one!(t(item), LibTmux.Filter.input()) :: item
when item: LibTmux.Schema.observation()
```

Returns exactly one match or raises its cardinality error.

# `one_or_nil`

```elixir
@spec one_or_nil(t(item), LibTmux.Filter.input()) ::
  {:ok, item | nil} | {:error, LibTmux.Error.t()}
when item: LibTmux.Schema.observation()
```

Returns one match or nil; a second match remains an error.

# `one_or_nil!`

```elixir
@spec one_or_nil!(t(item), LibTmux.Filter.input()) :: item | nil
when item: LibTmux.Schema.observation()
```

Returns one match or nil, raising on multiple matches.

# `size`

```elixir
@spec size(t()) :: non_neg_integer()
```

Returns cached materialized size in constant time.

# `where`

```elixir
@spec where(t(item), LibTmux.Filter.input()) :: t(item)
when item: LibTmux.Schema.observation()
```

Filters validated data while retaining order and captured graph context.

---

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