3 ms·
Actually I'd like this with x = foo() y = bar(x) z = baz(y) blah(z) else err -> handle_err(err) end
by pmontra 8y ago
Actually I'd like this
with
x = foo()
y = bar(x)
z = baz(y)
blah(z)
else
err -> handle_err(err)
end
No do (uselessly verbose, it litters all the language) and = instead of <-
It should be normal code and take the else branch whenever there is any error, pattern matching included. The advantage is that the code can be indented in or out a with block, without any change. Much more convenient.
Elixir also have a try/catch
https://elixir-lang.org/getting-started/try-catch-and-rescue.html https://elixir-lang.org/getting-started/try-catch-and-rescue...
> In Elixir, we avoid using try/rescue because we don’t use errors for control flow. We take errors literally: they are reserved for unexpected and/or exceptional situations.
- PopeDotNinja 8y ago> No do (uselessly verbose, it litters all the language) and = instead of <- It should be normal code and take the else branch whenever there is any error, pattern matching included. Using '=' insead of '<-' would break how with works. I can understand why one thinks the syntax looks weird. I avoid with when possible, but sometimes it's the easiest abstraction to use.