|
|
|
|
|
by Leftium
654 days ago
|
|
I'm waiting for pattern matching to be added to JS. The proposal[1] documents a lot of thought on how to add pattern matching to a language, including prior art in other languages. (Pattern matching was introduced to me via either F# or Erlang/Elixir.) DeltaScript pattern matching seems to be missing two major features; perhaps intentional because the implementation is more difficult: 1. Binding - useful to be able to assign variables to sub-parts of the control value. 2. Structural matching - matching based on the shape of the control value. I suppose both binding and structural matching can be accomplished with more verbose `passes` tests. (Also some redundant code to get the bindings; perhaps the `passes` test could return optional bindings.) [1]: https://github.com/tc39/proposal-pattern-matching |
|
I'll link that post for reference: https://www.reddit.com/r/ProgrammingLanguages/comments/1fb5y...
The gist (hehe) was that a full lambda expression in a `passes` case could often feel like overkill. This was the possible solution I suggested:
Here is a structural matching example: