View Source Reactor.Argument.Templates (reactor v0.2.4)

Template functions used to declare DSL arguments.

Link to this section Summary

Functions

The input template helper for the Reactor DSL.

The result template helper for the Reactor DSL.

The value template helper for the Reactor DSL.

Link to this section Functions

@spec input(atom()) :: Reactor.Template.Input.t()

The input template helper for the Reactor DSL.

example

Example

defmodule ExampleReactor do
  use Reactor

  input :name

  step :greet do
    # here: --------↓↓↓↓↓
    argument :name, input(:name)
    impl fn
      %{name: nil}, _, _ -> {:ok, "Hello, World!"}
      %{name: name}, _, _ -> {:ok, "Hello, #{name}!"}
    end
  end
end
@spec result(atom()) :: Reactor.Template.Result.t()

The result template helper for the Reactor DSL.

example

Example

defmodule ExampleReactor do
  use Reactor

  step :whom do
    impl fn ->
      {:ok, Enum.random(["Marty", "Doc", "Jennifer", "Lorraine", "George", nil])}
    end
  end

  step :greet do
    # here: --------↓↓↓↓↓↓
    argument :name, result(:whom)
    impl fn
      %{name: nil}, _, _ -> {:ok, "Hello, World!"}
      %{name: name}, _, _ -> {:ok, "Hello, #{name}!"}
    end
  end
end
@spec value(any()) :: Reactor.Template.Value.t()

The value template helper for the Reactor DSL.

example

Example

defmodule ExampleReactor do
  use Reactor

  input :number

  step :times_three do
    argument :lhs, input(:number)
    # here: -------↓↓↓↓↓
    argument :rhs, value(3)

    impl fn args, _, _ ->
      {:ok, args.lhs * args.rhs}
    end
  end
end