One line `with` with else

Hi folks!

I am using Elixir 1.3.3.

One line if works just fine:

iex(3)> if true, do: :ok, else: :error
iex(4)> if false, do: :ok, else: :error

One line with works fine without else:

iex(5)> with true <- true, do: :ok

One line with with else does not work:

iex(6)> with true <- true, do: :ok, else: {:error, _msg} -> :error
** (SyntaxError) iex:6: syntax error before: '->'

Maybe someone knows the reason.


When using the one-liner syntax with ->, you need to wrap the whole left -> right expression in parens otherwise it is unable to know where it starts and where it finishes:

iex(1)>  with true <- true, do: :ok, else: ({:error, _msg} -> :error)

Great! Thank you very much, José!