Cizen v0.12.5 Cizen.Effect behaviour View Source

The effect behaviour.

Example

defmodule Repeat do
  use Cizen.Effect
  use Cizen.Effects, only: [Chain]
  defstruct [:count, :effect, :pid]
  @impl true
  def expand(id, %__MODULE__{count: count, effect: effect, pid: pid}) do
    effects =
      [effect]
      |> Stream.cycle()
      |> Enum.take(count)

    %Chain{
      effects: effects
    }
  end
end

Link to this section Summary

Link to this section Types

Link to this type alias_of() View Source
alias_of() :: {:alias_of, t()}
Link to this type consume() View Source
consume() :: {:consume, term()}
Link to this type resolve() View Source
resolve() :: {:resolve, term()}

Link to this section Functions

Link to this function handle_event(handler, event, effect, state) View Source
handle_event(handler(), Cizen.Event.t(), t(), state :: term()) ::
  resolve() | consume() | term()
Link to this function init(handler, effect) View Source
init(handler(), t()) :: resolve() | {t(), term()}

Link to this section Callbacks

Link to this callback expand(handler, t) View Source
expand(handler(), t()) :: t()
Link to this callback handle_event(handler, arg1, t, state) View Source
handle_event(handler(), Cizen.Event.t(), t(), state :: term()) ::
  resolve() | consume() | term()
Link to this callback init(handler, t) View Source
init(handler(), t()) :: resolve() | alias_of() | term()