The |>
(pipe) operator introduces the expression on the left-hand side as the first argument to the function call on the right-hand side. True to functional programming, we treat our programs as a series of data transformations.
The above is equivalent to:
The above code appears in reverse order, where earlier operations are inner expressions. We have to start from the middle and read outwards to understand the sequence. Using pipes leads to a clearer sequence of operations.
Here’s another example taken from the Ecto database wrapper:
Additional reading: