tc39 / proposal-pattern-matching

Pattern matching syntax for ECMAScript
https://tc39.es/proposal-pattern-matching/
MIT License
5.51k stars 89 forks source link

Custom Matchers potentially improve Map and Set objects #335

Closed NagayamaToshiaki closed 4 days ago

NagayamaToshiaki commented 5 days ago

For now, Map object and Set object is useless for mapping some objects (unless you stringify them) because objects are compared by reference, thus virtually every object is considered different.

However, with advent of custom matchers, you can declare the way to compare them as you want. If you can apply the matcher to the comparison methods inside Map, you can use objects as Map 's key as excepted.

Is there any plans to other enhancements with custom matchers?

ljharb commented 4 days ago

We're not planning on any changes to Map or Set in this proposal.

However, you could certainly combine https://github.com/tc39/proposal-richer-keys and this proposal to use pattern matching as your key normalization/comparison mechanism.

NagayamaToshiaki commented 4 days ago

Thank you for the info! I`ll close this.