# selection.Selection

- **Module:** selection
- **Package:** libtmux
- **Language:** TypeScript
- **Kind:** interface
- **Source:** https://github.com/libtmux/libtmux-ts/blob/3fe1ca654b81b8cbf4a13b777a001a3298c87a6f/packages/libtmux/src/selection.ts#L341
- **Page:** https://libtmux.org/en/ts/latest/reference/selection-selection/

An immutable, ordered set of tmux objects read at one instant.

A Selection is deliberately not an Array. It is `Iterable` and it never
changes, so the answer it gave a moment ago is still the answer now — which
is what lets a snapshot be reasoned about at all. `toArray()` is the one
crossing to array semantics, and everything Array offers that this does not
lives on the other side of it.

Two ways to narrow, never overloaded into each other: `where` takes
declarative criteria that are data — serializable, inspectable, sendable over
a wire — and `filter` takes an ordinary predicate. Reach for `where` unless
the question genuinely needs to run code.

## Members

- `length` (property): How many members this holds. Unlike `count`, it takes no criteria.
- `[Symbol.iterator]` (method): Iterate in tmux's own order.
- `at` (method): The member at `index`, or undefined when the index is out of range.
- `toArray` (method): A plain array of the members, in order.
- `map` (method): Apply `transform` to each member, in order.
- `filter` (method): Keep the members `predicate` accepts.
- `where` (method): Keep the members matching declarative criteria.
- `first` (method): The first member, or the first matching `criteria`.
- `one` (method): The single member, or the single one matching `criteria`.
- `oneOrUndefined` (method): The single member, or undefined when there is none.
- `exists` (method): Whether anything matches. Cheaper to read than comparing a count to zero.
- `count` (method): How many members match `criteria`, or how many there are without it.
