Elixir: Pipe Operator: |>

Using the |> operator in a function

nick3499
1 min readJul 12, 2017
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.

--

--

nick3499
nick3499

Written by nick3499

coder of JavaScript and Python

No responses yet