Skuld.Effects.Port.EffectfulContract (skuld v0.23.0)
View SourceGenerates an effectful behaviour from a HexPort.Contract.
use Skuld.Effects.Port.EffectfulContract reads the operations from a
plain HexPort contract and generates:
- Effectful
@callbackdeclarations withcomputation(return_type)return types on the using module __port_operations__/0— copied from the HexPort contract__port_effectful__?/0— marker for effectful resolver auto-detection
The effectful contract module is the effectful behaviour. Effectful
implementations declare @behaviour MyApp.Todos.Effectful.
Usage
# Plain contract (HexPort)
defmodule MyApp.Todos.Contract do
use HexPort.Contract
defport get_todo(id :: String.t()) :: {:ok, Todo.t()} | {:error, term()}
end
# Effectful contract (Skuld)
defmodule MyApp.Todos.Effectful do
use Skuld.Effects.Port.EffectfulContract,
hex_port_contract: MyApp.Todos.Contract
end
# Effectful facade
defmodule MyApp.Todos do
use Skuld.Effects.Port.Facade, contract: MyApp.Todos.Effectful
endEffectful Implementation
defmodule MyApp.Todos.EffectfulImpl do
@behaviour MyApp.Todos.Effectful
def get_todo(id) do
Comp.pure({:ok, %Todo{id: id}})
end
endOptions
:hex_port_contract(required) — the HexPort contract module that defines__port_operations__/0viause HexPort.Contract.