# `Skuld.Comp.ScopeEnv`
[🔗](https://github.com/mccraigmccraig/skuld/blob/main/lib/skuld/comp/scope_env.ex#L1)

Scope machinery carried through a computation.

Groups the elements that define what scope a computation is running in:

- `evidence` — installed effect handlers
- `leave_scope` — cleanup chain for scoped effects
- `transform_suspend` — suspend decoration chain, also scoped
- `current_fiber_id` — set when executing inside a FiberPool fiber, nil otherwise

These are installed together via `scoped/2`, inherited together at fiber
spawn, and survive suspend/resume cycles together. They are the computation's
"scope structure" — the runtime context that determines how effects are handled.

## Relationship with Env

`ScopeEnv` is embedded in `Env.scope`. The `Env` module provides accessor
functions that delegate into `scope` so callers don't need to reach through
the nesting to read or mutate scope fields directly.

# `t`

```elixir
@type t() :: %Skuld.Comp.ScopeEnv{
  current_fiber_id: term() | nil,
  evidence: %{required(Skuld.Comp.Types.sig()) =&gt; Skuld.Comp.Types.handler()},
  leave_scope: Skuld.Comp.Types.leave_scope() | nil,
  transform_suspend: Skuld.Comp.Types.transform_suspend() | nil
}
```

# `current_fiber_id`

```elixir
@spec current_fiber_id(t()) :: term() | nil
```

Get the current fiber ID from scope, or nil

# `delete_handler`

```elixir
@spec delete_handler(t(), Skuld.Comp.Types.sig()) :: t()
```

Remove a handler for an effect signature

# `get_handler`

```elixir
@spec get_handler(t(), Skuld.Comp.Types.sig()) :: Skuld.Comp.Types.handler() | nil
```

Get the handler for an effect signature, or nil

# `get_leave_scope`

```elixir
@spec get_leave_scope(t()) :: Skuld.Comp.Types.leave_scope()
```

Get the current leave-scope handler (returns identity if nil)

# `get_transform_suspend`

```elixir
@spec get_transform_suspend(t()) :: Skuld.Comp.Types.transform_suspend()
```

Get the current transform-suspend handler (returns identity if nil)

# `handler_sigs`

```elixir
@spec handler_sigs(t()) :: [Skuld.Comp.Types.sig()]
```

Get all installed handler signatures

# `new`

```elixir
@spec new() :: t()
```

Create a fresh scope env with identity leave_scope and transform_suspend

# `put_current_fiber_id`

```elixir
@spec put_current_fiber_id(t(), term()) :: t()
```

Set the current fiber ID in scope

# `put_handler`

```elixir
@spec put_handler(t(), Skuld.Comp.Types.sig(), Skuld.Comp.Types.handler()) :: t()
```

Install a handler for an effect signature

# `with_leave_scope`

```elixir
@spec with_leave_scope(t(), Skuld.Comp.Types.leave_scope()) :: t()
```

Install a new leave-scope handler

# `with_transform_suspend`

```elixir
@spec with_transform_suspend(t(), Skuld.Comp.Types.transform_suspend()) :: t()
```

Install a new transform-suspend handler

---

*Consult [api-reference.md](api-reference.md) for complete listing*
