magritte v0.1.2 Magritte

Alternative pipe operator definition.

Usage

Just drop use Magritte at the top of your module and then follow with documentation for Margitte.|>/2 below.

Link to this section Summary

Functions

Enchanced pipe operator.

Link to this section Functions

Link to this macro

left |> right

(macro)

Enchanced pipe operator.

This operator introduces the expression on the left hand as an argument to the function call on the right hand. The position for given argument is determined by positopn of ... operator on the right. If that operator is not present, then it will use first position as a default.

Examples

iex> [1, [2], 3] |> List.flatten()
[1, 2, 3]

The example above is the same as calling List.flatten([1, [2], 3]).

You can pick the position where the result of the left side will be inserted:

iex> 2 |> Integer.to_string(10, ...)
"1010"

The example above is the same as calling Integer.to_string(10, 2).

You can also join these into longer chains:

iex> 2 |> Integer.to_string(10, ...) |> Integer.parse
{1010, ""}

The operator ... can be used only once in the pipeline, otherwise it will return compile-time error:

2 |> Integer.to_string(..., ...)
** (CompileError) Doubled placeholder in Integer.to_string(..., ...)