Skuld.Effects.Port.EffectfulContract (skuld v0.24.0)

View Source

Generates an effectful behaviour from a DoubleDown.Contract.

use Skuld.Effects.Port.EffectfulContract reads the operations from a plain DoubleDown contract and generates:

  • Effectful @callback declarations with computation(return_type) return types on the using module
  • __callbacks__/0 — copied from the DoubleDown 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 (DoubleDown)
defmodule MyApp.Todos.Contract do
  use DoubleDown.Contract

  defcallback get_todo(id :: String.t()) :: {:ok, Todo.t()} | {:error, term()}
end

# Effectful contract (Skuld)
defmodule MyApp.Todos.Effectful do
  use Skuld.Effects.Port.EffectfulContract,
    double_down_contract: MyApp.Todos.Contract
end

# Effectful facade
defmodule MyApp.Todos do
  use Skuld.Effects.Port.Facade, contract: MyApp.Todos.Effectful
end

Effectful Implementation

defmodule MyApp.Todos.EffectfulImpl do
  @behaviour MyApp.Todos.Effectful

  def get_todo(id) do
    Comp.pure({:ok, %Todo{id: id}})
  end
end

Options

  • :double_down_contract (required) — the DoubleDown contract module that defines __callbacks__/0 via use DoubleDown.Contract.