15:04
<rbuckton>

I'm confused by this example in the README.md, I don't think the 2nd parameter matches the proposed spec text:

RegExp.prototype[Symbol.customMatcher] = function(subject, {matchType}) {
    const result = this.exec(subject);
    if(matchType == "boolean") return result;
    if(matchType == "extractor") return [result, ...result.slice(1)];
}

Isn't the 2nd argument just a string, and aren't the possible values "boolean" and "list"?

15:12
<rbuckton>

Also, I'm not sure I agree with the result for a RegExp custom matcher as suggested here: https://github.com/tc39/proposal-pattern-matching?tab=readme-ov-file#regex-extractor-patterns

To match against a RegExp, you may want to match against either named capture groups, positional capture groups, or the whole match. I think the matcher could just be:

RegExp.prototype[Symbol.customMatcher] = function(subject, hint) {
    const result = this.exec(subject);
    if (hint === "boolean") return !!result;
    if (hint === "list") return result && [result];
}

And the pattern would look like:

when /(?<left>\d+) \+ (?<right>\d+)/({groups:{let left, let right}}): ...;
when /(\d+) \* (\d+)/([void, let left, let right]): ...;
when /\d+/([let digits]): ...;
15:15
<rbuckton>
The extra outputs from ...result.slice(1) seem like unnecessary overhead for the sake of convenience as I doubt engines will optimize them away if unused.
20:47
<TabAtkins>
I was kinda wanting to be able to do the second and third cases as just (void, let left, let right) and (let digits) rather than requiring an array pattern as well, but I suppose that's not a big deal, yeah.
21:03
<rbuckton>
(let digits) doesn't work if you want to access groups. (at least, not without the abandoned Foo{ } syntax).
21:08
<rbuckton>

I'm in the middle of writing some code using C#'s pattern matching and ran into an interesting mechanism. C# has an object initialization syntax that lets you write code like this:

var a = new Foo() {
  Bar = 1,
  Baz.Quxx = 2,
}

which amounts to

var a = new Foo();
a.Bar = 1;
a.Baz.Quxx = 2;

and { Baz.Quxx = 2 } is essentially the same as { Baz = { Quxx = 2 } }.

21:09
<rbuckton>
And unnamed types can be new { Bar, Baz.Quxx } which is essentially new { Bar = Bar, Quxx = Baz.Quxx }.
21:10
<rbuckton>
Apparently they have a similar shorthand syntax for pattern matching, x is { Bar: 1, Baz.Quxx: 2 }, which is the same as x is { Bar: 1, Baz: { Quxx: 2 } }.
21:11
<rbuckton>
Definitely not an MVP feature, but the deep property pattern seems potentially valuable and we're already parsing dotted names for extractors.
21:44
<TabAtkins>
yeah, not an mvp, but that's definitely something we might want to do in the future