clever, I had to stare at it for a few minutes to go through all the possibilities.
That's where the real beauty of a neatly syntaxed pattern matching expression could do a great deal to make it super obvious, what one wants to express with their code.
In more complex situations, it would be more appropriate to use object-oriented polymorphism (class support contains state rather than just functions)
ECMAScript Pattern Matching (if it ever lands) can clean up complex expression based data transformations considerably.
pattern matching would be awesome. I wanna have it everywhere
Sometimes the stars align and you get to "fake it" with a Bitwise OR (|):
clever, I had to stare at it for a few minutes to go through all the possibilities.
That's where the real beauty of a neatly syntaxed pattern matching expression could do a great deal to make it super obvious, what one wants to express with their code.
That's possibly because of lack of familiarity.
The Rust equivalent doesn't look that different to me:
in particular
In Erlang (and Elixir is similar) something like (again, assuming that the sides are sorted by length so that equal sides will always be adjacent)
or
ReScript (aka ReasonML; JavaScript flavored OCaml)
etc.
very likely.
And nice overview, of how different languages handle the same problem