I just ran into this unexpected behavior. I had a short function that is piping its result into other functions. When I converted the short function to a one-liner, the result changed.
I expected the EOL to terminate the if
/do
/else
and not for the else
only to be piped to the next line. (If you add parentheses around the if
/do
/else
line, it works the same as the multi-line function.)
What terminates a one-line function? Where else might this happen?
defmodule F do
def fn1() do
if true do
1
else
0
end
|> Kernel.+(10)
end
def fn2() do
if true, do: 1, else: 0
|> Kernel.+(10)
end
end
F.fn1() # returns 11
F.fn2() # returns 1