4 ms·
I’ve never used Elixir, but when I saw piping into case statements I was confused as to why it’s appearing on a ‘do not use’ list. It does seem awesome! The key
by cormacrelf 5y ago
I’ve never used Elixir, but when I saw piping into case statements I was confused as to why it’s appearing on a ‘do not use’ list. It does seem awesome! The key thing for error handling is to be able to do it inline, without introducing nesting, like those withs are doing. Maybe you don’t get that with case either. Does elixir have a return statement?
- pipingdog 5y agoElixir does not have a return keyword.
- jkhdigital 5y agoElixir, like Erlang, is functional so there are no statements. Everything is an expression, which evaluates to some value when executed. The “return” value is just the value of the last expression evaluated in the function call.
- cormacrelf 5y agoIs there an equivalent of the Haskell Either monad & do-notation / Rust Result + the ? (try) operator?
- mcintyre1994 5y agoSort of, there’s a convention used throughout the standard library of returning {:ok, output} or {:err, error} or nil. That makes it really easy to compose functions/check for errors. The equivalent of do-notation would be with statements I think: https://elixirschool.com/en/lessons/basics/control-structures/#with https://elixirschool.com/en/lessons/basics/control-structure...
- cormacrelf 5y agoohhhhhhhhh, with statements do sequential . Yep. I'm on board with the original post now. Thanks!