# Selectors

The examples run inside an [active graph](graph.fsx).

`createSelector source` is `createLookup` with `affected = fun prev next -> [ prev; next ]`: `Get key` is
`true` for the selected key and `false` for every other. A selection change wakes only the readers of
the previous and the next key.

```fsharp
let selected = createSignal 1
let isSelected = createSelector (fun () -> selected.Value)
```



```fsharp
selected.Value <- 3
[ for k in 1..4 -> k, isSelected.Get k ]
```

```text
[(1, false); (2, false); (3, true); (4, false)]
```

:::details Tests covering this behaviour

Pinned by `createSelector reports membership and wakes only the two ends` and
`only the affected keys are recomputed`
([Lookups.fs](https://github.com/shayanhabibi/Ranvier/blob/master/tests/Ranvier.Tests/Lookups.fs)).
:::

Move the selection from 1 to 2. Only those two membership values change; the reader for
key 3 stays quiet.

<div class="partas-solid-card partas-solid-card--map">

<div class="partas-solid" data-partas-page="p5e22b589f1" data-partas-cell="c1"></div>

</div>
