Elixir IEX multi-line command
A change on Elixir
1.12.0 made possible to pipe
|> multi-line commands in
iex where the
|> operator is in the beginning of new lines.
That means that we can:
iex(1)> :foo :foo iex(2)> |> to_string() "foo" iex(3)> |> String.upcase() "FOO"
The docs also mention that all other binary operators works the same way, except
-/2, so that's also valid:
iex(1)> [:foo] [:foo] iex(2)> ++ [:bar] [:foo, :bar] iex(3)> |> Enum.join(" ") "foo bar" iex(4)> |> String.upcase() "FOO BAR"
Each line will run at a new command, so if you assign a variable in the first line you may not have what you expect, so watch out.Tweet