Pattern matching would be a great addition to JS. I built a pattern matching library[1] with a very similar syntax back in 2015 (although I will be the first to admit that it's a naive implementation). It makes validating/traversing deeply-nested objects much less verbose. I'm excited to see where this proposal goes. [1] https://github.com/cshepp/Kasai
I rather like your syntax compared to the proposed version. It is less concise but must more consistent and parsable: return match(user, [ [{first: $, middle: $, last: $}, (f, m, l) => f + ' ' + m + ' ' + l], [{first: $, last: $} , (f, l) => f + ' ' + l], [_, 'unknown'] ]);
... so calling Object.keys() is not necessarily going to use a consistent ordering. I think that is why they have to use the more verbose syntax in the other library.
I think you could do something like: {first: $.0, middle: $.1, last: $.2}, (f, m, l) => ... pretty easily, though.