Skuld.Comp.Env (skuld v0.1.26)

View Source

Environment construction and manipulation.

The Env struct carries evidence (handlers), state, and the leave-scope chain. It supports extension fields - arbitrary atom keys can be added via Map.put/3.

Summary

Types

t()

The environment struct. Supports extension fields beyond the core struct keys (structs are maps, so Map.put(env, :custom_key, value) works).

Functions

Remove a handler for an effect signature

Get handler for an effect signature (returns nil if missing)

Get handler for an effect signature (raises if missing)

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

Get state for an effect

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

Create a fresh environment with identity leave-scope and transform-suspend

Update state for an effect

Install a handler for an effect signature

Install a new leave-scope handler

Install a new transform-suspend handler

Types

t()

@type t() :: %Skuld.Comp.Env{
  evidence: %{required(Skuld.Comp.Types.sig()) => Skuld.Comp.Types.handler()},
  leave_scope: Skuld.Comp.Types.leave_scope() | nil,
  state: %{required(term()) => term()},
  transform_suspend: Skuld.Comp.Types.transform_suspend() | nil
}

The environment struct. Supports extension fields beyond the core struct keys (structs are maps, so Map.put(env, :custom_key, value) works).

Functions

delete_handler(env, sig)

Remove a handler for an effect signature

get_handler(env, sig)

Get handler for an effect signature (returns nil if missing)

get_handler!(env, sig)

Get handler for an effect signature (raises if missing)

get_leave_scope(env)

@spec get_leave_scope(Skuld.Comp.Types.env()) :: Skuld.Comp.Types.leave_scope()

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

get_state(env, key, default \\ nil)

@spec get_state(Skuld.Comp.Types.env(), term(), term()) :: term()

Get state for an effect

get_transform_suspend(env)

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

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

new()

@spec new() :: Skuld.Comp.Types.env()

Create a fresh environment with identity leave-scope and transform-suspend

put_state(env, key, value)

@spec put_state(Skuld.Comp.Types.env(), term(), term()) :: Skuld.Comp.Types.env()

Update state for an effect

with_handler(env, sig, handler)

Install a handler for an effect signature

with_leave_scope(env, new_leave_scope)

Install a new leave-scope handler

with_transform_suspend(env, new_transform_suspend)

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

Install a new transform-suspend handler