# Scope


Computation-scoped handlers via effect rotation.

## `handlersFromAttrs`

_scope.handlersFromAttrs: lift an attrset of handlers, functions, or constants into named effect handlers; preserves shape and state._

```
handlersFromAttrs : { <name> = handler | (param -> a) | a; ... } -> handlers
```

Helper to transform an attrset into named handlers.

If attrValue is a function `{ param, state }` it is used directly as handler;
If attrValue is a function, resume is `f param` and preserves state;
Otherwise a constant handler always resumes with attrValue, preserving state.

## `provide`

_scope.provide: install stateless handlers for a sub-computation's dynamic extent (reader/val pattern); outer handler state survives unchanged._

```
scope.provide : handlers -> Computation a -> Computation a
```

Install handlers for a computation's dynamic extent without
touching state. Unhandled effects rotate outward; outer handler
state mutations survive unaffected.

This is the reader/val handler pattern (Koka's `val`, Haskell's
`runReader`, Scheme's `parameterize`) — use it when handlers are
stateless (resume with a constant, pass state through).
For handlers that need their own state, use scope.run or
scope.stateful instead.

## `run`

_scope.run: handle named effects inside a sub-computation and hide the scope's own state from the caller; rotates unknown effects outward._

```
scope.run : { handlers, state? } -> Computation a -> Computation a
```

Run a computation with scoped handlers. Effects matching `handlers`
are handled inside the scope. Unknown effects rotate outward.
The scope's internal state is hidden — caller sees only the body's value.

## `runWith`

_scope.runWith: like scope.run but surfaces the scope's final `{ value, state }` to the caller; raw rotation without state hiding._

```
scope.runWith : { handlers, state? } -> Computation a -> Computation { value, state }
```

Like scope.run but exposes the scope's final state alongside the value.

## `stateful`

_scope.stateful: run a sub-computation under scoped handlers while preserving outer state around the rotation point; wraps state.update._

```
stateful : handlers -> Computation a -> Computation a
```

Run a computation with scoped handlers while preserving
state around effect rotation.

## `val`

_scope.val: provide constant values as named effect handlers for a sub-computation; sugar for `provide (handlersFromAttrs bindings)`._

```
scope.val : { <name> = value; ... } -> Computation a -> Computation a
```

Provide constant values as named effect handlers for a
computation's dynamic extent. Each key in the bindings attrset
becomes an effect that resumes with the corresponding value.
Built on scope.provide via handlersFromAttrs.

Named after Koka's `val` effect handler. For the traditional
single-environment reader (ask/asks/local), see fx.effects.reader.

