# State


Mutable state effect: get/put/modify with standard handler.

## `get`

_get: read the current state threaded by the state handler; impure request whose response IS the handler state._

```
get : Computation s
```

Read the current state. Returns a Computation that, when handled,
yields the current state value.

## `gets`

_gets: read a projection of the current state via a user function; sugar for `bind get (s: pure (f s))`._

```
gets : (s -> a) -> Computation a
```

Read a projection of the current state.

## `handler`

_state.handler: interprets get/put/modify over a single state value; pair with `trampoline.handle` and the initial state._

Standard state handler. Interprets get/put/modify effects.
Use with `trampoline.handle`:

```nix
handle { handlers = state.handler; state = initialState; } comp
```

- `get`: returns current state as value
- `put`: replaces state with param, returns null
- `modify`: applies param (a function) to state, returns null

## `modify`

_modify: apply a function to the current state in place; impure request resuming with null after the handler runs the transformer._

```
modify : (s -> s) -> Computation null
```

Apply a function to the current state. Returns a Computation that,
when handled, transforms the state via f and returns null.

## `put`

_put: replace the current state with the supplied value; impure request resuming with null._

```
put : s -> Computation null
```

Replace the current state. Returns a Computation that, when handled,
sets the state to the given value and returns null.

## `update`

_update: read the state, run a user computation against it to produce `{ state, value }`, put the new state, return the value._

```
update : (s -> Computation { state, value }) -> Computation value
```

Apply a computation to the current state. Returns a Computation that,
when handled, updates the state and returns value.

