Hacker News new | ask | show | jobs
by metadat 756 days ago
The `maybe_expr' meta pattern matching fallback mechanic is nice, and can surely help avoid a lot of boilerplate code while simultaneously encapsulating the logic in a structure which is easy to read and reason about. It's also not a thing in any other programming language I've learned- C, Java/Scala/C#/C++, Go, Javascript, Tcl, Bash(lol), PHP, Forth, ML, and so on.

I had to look up it's usage though, because I'm new to both Erlang/BEAM and Elixir.

https://chiroptical.dev/posts/2024-03-04-erlang-maybe_expr.h...

1 comments

You do realize that Rust, C#/F#, Kotlin/Scala, now Java to an extent, pretty much all FP and many other languages have extensive pattern matching support?
In fairness, it's doing a bit more than "just" pattern matching. It's very similar to the `with` expression in elixir: https://hexdocs.pm/elixir/1.16.3/Kernel.SpecialForms.html#wi...

You can use it to execute a series of functions returning `either`-ish tuples and build up a railway oriented program.

It goes beyond your typical pattern matching, check out the link in my first post if you're curious to learn!