Hacker News new | ask | show | jobs
by sergiotapia 2374 days 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.
3 comments

I 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.
Yup, 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.
Basically 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.

There seem to be plans to extend this to destructuring assignment/bind, that would be a ton more useful and interesting imo.
My first exposure to it was in Haskell. It felt very surreal and almost magical at the time.