Open Pyrolistical opened 2 years ago
What about block params would work well with pattern matching?
Sorry, I could have provided an example.
This tc39 proposal pattern matching syntax
when ({ status: 200, body, ...rest }):
handleData(body, rest)
is the like proposal block params do expression (note the first rest
is now a matcher, not destructuring)
when ({ status: 200, body, rest }) do (body, rest) {
return handleData(body, rest)
}
which is implementable in patcom today as
when ({ status: 200, body, rest }, (body, rest) => {
return handleData(body, rest)
})
It wouldn't be possible to write a tc39 proposal pattern matching polyfill. I take that back. But you could get very close to the intent.
Sure, i see how with block params and a when
function you could simulate parts of it - but you could do the same with a callback function, no?
Yes, you can do same with callback, but the motivation of this proposal it to provide better syntax for callback/blocks.
Note this proposal also include a nest block feature, so in pattern match case, it should be possible to write
match (value) do {
::when ({ status: 200, body: defined, rest }) do (body, rest) {
return handleData(body, rest)
}
}
Actually it's a little bit like Raku pattern match, you could execute any statements in match block.
I really like block params as it would generalize the syntax https://github.com/tc39/proposal-pattern-matching is trying to add.
Which happens to what I incidentally did using with patcom
See example
We could probably write a tc39 proposal pattern matching polyfill using a block params polyfill + patcom.