tc39 / proposal-upsert

ECMAScript Proposal, specs, and reference implementation for Map.prototype.upsert
https://tc39.es/proposal-upsert/
MIT License
202 stars 14 forks source link

Has the `entry` api from Rust's `HashMap` been considered? #42

Closed rope-hmg closed 1 month ago

rope-hmg commented 3 years ago

Following from an earlier issue about this api being quite verbose. I agree with the concerns raised there, but I don't think the proposed solution is great.

Personally I think a particularly elegant solution to this problem is the entry api from Rust's HashMap. https://doc.rust-lang.org/nightly/std/collections/hash_map/struct.HashMap.html#method.entry

Here is an implementation in JS that I use in some projects: https://www.npmjs.com/package/rust-map

The only problem I can think of with this is what happens if someone retains the Entry object returned from this call. Maybe it's not actually an issue?

rope-hmg commented 3 years ago

Well, I've just re-read the FAQ and noticed there is a section that mentions an entry api. I guess it is more of an issue than I first thought.

As far as ergonomics go I don't think the current proposal offers much over the existing api.

dminor commented 1 month ago

This is outside of the scope of the current proposal.