`with` tweak feature request - first clause on new line

I had been using the backslash method, and it worked in testing - but I hadn’t added the comment on the next line yet! When I did add a comment on the proceeding line, it didn’t compile and I had a heck of a time figuring out that the with \ method doesn’t like comments on the following line!

So the following is valid:

test "with, comma-do, newline, backslash" do
  :ok =
    with \
      :ok <- :ok,
      :ok <- :ok,
      do: :ok
end

But adding a comment invalidates the syntax:

# Doesn't compile
test "with, comma-do, newline, backslash, comments" do
  :ok =
    with \
      # Comment here <<<< Won't compile because of this line
      :ok <- :ok,
      :ok <- :ok,
      do: :ok
end

Fortunately, your answer pointed me to the solution using parentheses, but it was tricky (for me :wink: ) to get them to work with a do-else-end block. Here is the working final product:

test "with, do block, newline, parens, comments, else" do
  :ok =
    with(
      # Comment here
      :ok <- :ok,
      :ok <- :ok) do
      :ok
    else
      error -> :error
    end
end

Notice that the close paren goes before the do clause. I’ve uploaded a GitHub gist with the various syntaxes tried.

@josevalim I’m sure you and many others are aware of the with syntax nuances, but I am posting this to help anyone else who wants to combine the awesomeness of comments with the awesomeness of with. :smile: Thanks again for your help.