Simplificator3000.Helpers.PipelineHelpers (Simplificator3000 v0.7.0)
Link to this section Summary
Functions
A pipeline-if. This macro can be placed into the pipeline to wrap given body with a given condition so that the body is called only upon successful condition. Else branch can be supplied for alternate actions with the pipeline value.
Link to this section Functions
A pipeline-if. This macro can be placed into the pipeline to wrap given body with a given condition so that the body is called only upon successful condition. Else branch can be supplied for alternate actions with the pipeline value.
parameters
Parameters
ctx- Passed from pipeline.ctx_var- Your alias for the from-pipeline given value (supports unwrappinglike %{hello: world} = x)condition- Regular condition that is passed as-is to theKernel.ifopts- Passdoand (optionally)elseblocks to your liking (these are as well passed toKernel.ifas-is)
examples
Examples
iex> x = %{hello: :world}
iex> x |>
...> pif %{hello: hello_value} = x_alias, hello_value == :world do
...> Map.put(x_alias, :result, {hello_value, :yes})
...> else
...> Map.put(x_alias, :result, {hello_value, :no})
...> end
%{hello: :world, result: {:world, :yes}}
iex> x = %{hello: :world}
iex> x |>
...> pif %{hello: hello_value} = x_alias, hello_value == :invalid do
...> Map.put(x_alias, :result, {hello_value, :yes})
...> else
...> Map.put(x_alias, :result, {hello_value, :no})
...> end
%{hello: :world, result: {:world, :no}}
iex> x = %{hello: :world}
iex> x |>
...> pif %{hello: hello_value} = x_alias, hello_value == :invalid do
...> Map.put(x_alias, :result, {hello_value, :yes})
...> end
x