Skuld.Comp.IHandle behaviour (skuld v0.2.3)
View SourceBehaviour for effect operation handlers.
Implementing this behaviour provides:
- LSP autocomplete for the
handle/3callback signature - Compile-time warnings if the callback is missing or has wrong arity
- Public
handle/3function that can be referenced as&Module.handle/3
Example
defmodule MyEffect do
@behaviour Skuld.Comp.IHandle
@impl Skuld.Comp.IHandle
def handle(%Get{}, env, k) do
value = Env.get_state(env, @state_key)
k.(value, env)
end
@impl Skuld.Comp.IHandle
def handle(%Put{value: v}, env, k) do
new_env = Env.put_state(env, @state_key, v)
k.(:ok, new_env)
end
end
# Install handler:
comp |> Comp.with_handler(MyEffect, &MyEffect.handle/3)See Also
Skuld.Comp.IIntercept- for effects supporting catch clause interceptionSkuld.Comp.IInstall- for effects supporting catch clause handler installation
Summary
Callbacks
Handle an effect operation.
Callbacks
@callback handle(args :: term(), env :: Skuld.Comp.Types.env(), k :: Skuld.Comp.Types.k()) :: {Skuld.Comp.Types.result(), Skuld.Comp.Types.env()}
Handle an effect operation.
Receives:
args- the operation arguments (e.g.,%Get{},%Put{value: v})env- the current environmentk- the continuation to invoke with the result
Must return {result, env} - either by calling k.(value, env) or
by returning a sentinel like {%Skuld.Comp.Throw{}, env}.