-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Add a Map#merge function #2644
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Added Area-Library, Triaged labels. |
This comment was originally written by @seaneagan I think both mutative and non-mutative versions would be useful: // mutative However, an Object#clone would make non-mutative versions of APIs slightly less necessary: var merged = map.clone().putAll(otherMap); Though I'm not sure whether cloning an Map/List/etc. should produce another immutable object in which case this wouldn't work. |
This comment was originally written by @seaneagan Nevermind about Object#clone, looks like someone with much more experience has discoverered that copy constructors are superior: http://www.artima.com/intv/bloch13.html So my example would instead be: var merged = new Map.from(map).putAll(otherMap); which isn't so bad. |
FYI: HashMap and LinkedHashMap both have an addAll() method, but Map does not. The analyzer just starting reporting warnings for objects typed Map, and it looked like to a lot of people that Map had just removed addAll() Set owner to @floitschG. |
I must admit I thought Map had an addAll method, which is why I implemented it in HashMap. If we add addAll, we should also consider having addMissing, where addAll uses the argument map's value if both have the key, and addMissing uses the original value. |
This comment was originally written by @seaneagan instead of: map.addMissing(otherMap); in many cases one could mutate otherMap: otherMap.addAll(map); or create a new Map: var merged = new Map.from(otherMap)..addAll(map); |
I agree. No need to implement I don't like the Ok to add Added Ready-to-implement, Accepted labels. |
Added Fixed label. |
This issue was originally filed by @MarkBennett
What steps will reproduce the problem?
What is the expected output? What do you see instead?
The Map interface should define a merge function which merges together two Maps.
What version of the product are you using? On what operating system?
Version 0.1.0.201204121423, Build 6479
Dart SDK version 6478, Dartium version
The text was updated successfully, but these errors were encountered: