Both Java and Python (and others, surely) have a method on maps to add entries (putAll and update).
Map permits an iterable of entries to the constructor, but has no way to simply add an iterable of entries to an existing map. The current typical code is:
mapA.forEach((val, key) => {mapB.set(key, val)});
or
for (const [key, val] of mapA) {
mapB.set(key, val);
}
Rather, I'd expect to be able to do the following, as I would in Java or Python:
mapA.addEntries(<iterable>)
where <iterable> is another map, the result of Object.prototype.entries(), or anything else that gives 2-value tuples of key-value pairs.
The best method name is up for debate, but contenders would be addEntries, extend, addAll.
My friend Brad made a good point -- such a method would likely allow a performance improvement over the current iterate-and-set solution (in addition to being more concise and understandable).
I’ve wanted this many times. Seems like it would be an uncontroversial addition to me.
I’d expect a corresponding update to Set. There is an active Set prototype methods proposal, but I don’t think there’d be overlap, because Set.prototype.union is for creating a new Set, rather than for adding items to the receiver set.