Hacker News new | ask | show | jobs
by mattbierner 2985 days ago
I would prefer `match { ... } (value)`, with the `match` keyword essentially creating a function that does the matching when it invoked. Minor seeming change, but then you can think of match as being a generalization of arrow functions instead of a special new language construct (i.e., `(...args) => ...` is just shorthand for `match { ...args => ... }`)

I can understand why though they went with similar syntax to a switch statement though

2 comments

This might be too cute, but you could support both unambiguously: match (subject) { ... } and match { ... }.
This wouldn't work if the match contained eg. break or return.
Yes, if match is an expression than this restriction is the correct design in my opinion