Does `compositeKey` solve my problem?

This question is mostly for @bmeck, but I have a problem that the compositeKey proposal sounds like it might solve, and I wanted to explore it as a solution.

I represent a pixel as an object with the properties x, y, where x and y are the coordinates. I’d like to be able to use a Set with these objects such that an object with the same x and y values is treated as the same object. That is, the function that the Set uses for whether the objects are equal isn’t object identity but is instead based on the values.

Is this a good use case for compositeKey? If so, is it far enough along that I could use a version of it in a Node.js environment?

Thanks!

Yes, compositeKey would solve your problem. In addition if your types are not requiring anything more than numbers, Records would also work. For now though, compositeKey is able to be polyfilled, while Records/Tuples cannot be.

The proposal hasn’t seen much progress due to my attention being elsewhere but the npm module is certainly usable, but subject to API changes if the proposal progresses.

1 Like

Awesome, thanks for the quick response! I’ll check it out.