4 ms·
Pattern matching is awesome in Elixir, it's great to see functional language traits stain the Ruby language more. It's all the better for it.
by sergiotapia 7y ago
Pattern matching is awesome in Elixir, it's great to see functional language traits stain the Ruby language more. It's all the better for it.
- papito 7y agoI was introduced to it in Scala. I like how all "classic" languages are cherry-picking features from functional programming. It will make people less shell-shocked in the future, when they try it for real.
- nobleach 7y agoYup, Scala, F#/OCaml and Rust have the best pattern matching implementations I've seen. I'm happy to see other languages slowly coming around. Java has a JEP for it (although nowhere near as nice as Scala's). Even JavaScript has a TC-39 proposal, although its champion has gone on to focus more on Rust. I'm excited for the future.
- omneity 7y agoMy first exposure to it was in Haskell. It felt very surreal and almost magical at the time.
- pmontra 7y agoBasically this is Elixir's case, so a very narrow instance of what Elixir's pattern matching is. I'd love to see more pattern matching added to Ruby year after year. However adding everything Elixir has probably would require a total rework of the language. Example: multiple method definitions, one per pattern. I wonder what's going to be the idiomatic way to handle a failed match. Elixir ends the process but there is likely a supervisor to restart it. In the case of Ruby the process ends and there is nothing to restart it. In the case of Rails I expect the web request to fail with a 500 and maybe the next one will get more luck.
- riffraff 7y agoThere seem to be plans to extend this to destructuring assignment/bind, that would be a ton more useful and interesting imo.