# Choice


Non-deterministic choice effect: choose/fail/guard with list handler.

## `choose`

_choose: non-deterministic selection from a list of alternatives; the handler determines exploration strategy (e.g. listAll for all branches)._

```
choose : [a] -> Computation a
```

Non-deterministic choice from a list of alternatives. The handler
determines how alternatives are explored.

## `fail`

_fail: abort the current non-deterministic branch; equivalent to `choose []` with an empty-alternatives short-circuit._

```
fail : Computation a
```

Fail the current branch of non-deterministic computation.
Equivalent to `choose []`.

## `guard`

_guard: continue when the predicate is true, fail the branch when false; threads boolean predicates into non-deterministic search._

```
guard : bool -> Computation null
```

Guard a condition: continue if true, fail if false.

## `initialState`

_choice.initialState: starting state `{ results = []; pending = []; }` for the listAll handler; pair with `handle` to run._

Initial state for the listAll handler.

## `listAll`

_choice.listAll: handler exploring every non-deterministic branch and accumulating results into `state.results`; list-monad semantics._

Handler that explores all non-deterministic branches and returns
a list of all results. Empty choices abort that branch.

State is `{ results : [a], pending : [Computation a] }`.
After handling, results are in `state.results`.

```nix
let r = handle { handlers = choice.listAll; state = choice.initialState; } comp;
in r.state.results
```

