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

Link to this macro

pif(ctx, ctx_var, condition, opts)

(macro)
@spec pif(term(), term(), any(), keyword()) :: term()

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 unwrapping like %{hello: world} = x)
  • condition - Regular condition that is passed as-is to the Kernel.if
  • opts - Pass do and (optionally) else blocks to your liking (these are as well passed to Kernel.if as-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