Chain v0.1.0 Chain View Source
Chain is inspired by the Railway programming and JavaScript well known Promise API.
Its purpose is to ease the construction of multi-step data processing in a more readable manner than using elixir
native with macro.
Chain is more flexible than a with macro as the error recovery can be placed where you want.
Chains can be passed as parameters like Ecto.Multi objects, and called once (synchronously) using &Chain.run/1
Link to this section Summary
Functions
Initialize a new Chain with an initial value and options for the chain execution.
To add success steps to the chain call &Chain.next/2
To add recover steps to the chain call &Chain.recover/2
Adds a step to the chain. A step is a function of arity 1
Adds a recover step to the chain.
Executes the chain.
Returns the result from the last function executed.
(either a {:ok, value} or a {:error, reason} if a failure was not recovered)
Link to this section Functions
Initialize a new Chain with an initial value and options for the chain execution.
To add success steps to the chain call &Chain.next/2
To add recover steps to the chain call &Chain.recover/2
The result wil be automatically wrapped in a {:ok, value} if the result is neither {:ok, value} nor
{:error, reason}.
If the initial value is either a value or {:ok, value}, it will go the nearest next step.
If the initial value is {:error, reason} then the reason will be passed to the next recover step.
Adds a step to the chain. A step is a function of arity 1
It takes the result of the previous steps as parameter, and its result will be the parameter of the following step.
Adds a recover step to the chain.
Executes the chain.
Returns the result from the last function executed.
(either a {:ok, value} or a {:error, reason} if a failure was not recovered)