The readme example has
match (arithmeticStr) {
when (/(?<left>\d+) \+ (?<right>\d+)/) as { groups: { left, right } } { process(left, right); }
else { ... }
}
where the as { groups: { left, right } } is after when ( ... ). However, I think it should have been
match (arithmeticStr) {
when (/(?<left>\d+) \+ (?<right>\d+)/ as { groups: { left, right } } ) { process(left, right); }
else { ... }
}
since it can be extended for nested cases:
match (res) {
when ({
input: /(?<left>\d+) \+ (?<right>\d+)/) as { groups: { left, right } },
direction: 'N' | 'S' | 'W' | 'E',
}) { process(left, right, direction); }
else { ... }
}
Your first two examples seem equivalent to me, so I'm not sure how "should have" figures in. Can you elaborate?
(your third example should certainly work as-is)
I do want to note that there is some debate on the semantics of as and with - see #188 for more context. Do some of the code samples in this comment clear things up for you?
@mpcsh @ljharb Thanks! I confused as with with in previous examples. https://github.com/tc39/proposal-pattern-matching/issues/188#issuecomment-837783929 works for me.
Most helpful comment
@mpcsh @ljharb Thanks! I confused
aswithwithin previous examples. https://github.com/tc39/proposal-pattern-matching/issues/188#issuecomment-837783929 works for me.