In chains of pipes in Elixir, it's standard to place the pipe at the beginning on the line:
1
|> IO.inspect(label: "initial value")
|> Kernel.+(1)
|> IO.inspect(label: "plus one")
|> Kernel.*(2)
|> IO.inspect(label: "times two")
|> Integer.to_string(2)
|> IO.inspect(label: "in binary")
However, when I try to do this in IEx, the following happens:
iex(1)> 1
1
iex(2)> |> IO.inspect(label: "initial value")
** (SyntaxError) iex:2:1: syntax error before: '|>'
It is possible to workaround by moving the pipe operator to the end of the line:
iex(1)> 1 |>
...(1)> IO.inspect(label: "initial value") |>
...(1)> Kernel.+(1) |>
...(1)> IO.inspect(label: "plus one") |>
...(1)> Kernel.*(2) |>
...(1)> IO.inspect(label: "times two") |>
...(1)> Integer.to_string(2) |>
...(1)> IO.inspect(label: "in binary")
initial value: 1
plus one: 2
times two: 4
in binary: "100"
"100"
But that's tedious and unidiomatic. Is it possible to use pipes in IEx with the pipe on the next line, like we do in source files?