Elixir: Pipe Operator: |>

Using the |> operator in a function

flatten.ex

IEx CLI Example

iex(1)> c("flatten.ex")
[Flat]
iex(2)> Flat.flatten()
[2, 4, 6]

[1, [2], 3][1, 2, 3][2, 4, 6]

The nested [1, [2], 3] becomes the first argument passed to List.flatten, using the |> pipe operator. Next, the flattened [1, 2, 3] becomes the first argument passed to Enum.map(fn x -> x * 2 end) which returns [2, 4, 6] to the CLI.