View Source Reactor.Dsl.Argument (reactor v0.3.0)
The struct used to store argument DSL entities.
See d:Reactor.step.argument.
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 Types
@type t() :: %Reactor.Dsl.Argument{ __identifier__: any(), name: atom(), source: Reactor.Template.Input.t() | Reactor.Template.Result.t() | Reactor.Template.Value.t(), transform: nil | (any() -> any()) | {module(), keyword()} | mfa() }
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)
run 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
run fn ->
{:ok, Enum.random(["Marty", "Doc", "Jennifer", "Lorraine", "George", nil])}
end
end
step :greet do
# here: --------↓↓↓↓↓↓
argument :name, result(:whom)
run 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)
run fn args, _, _ ->
{:ok, args.lhs * args.rhs}
end
end
end