-
Notifications
You must be signed in to change notification settings - Fork 16
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
optional merge strategies for lists/sets #10
Comments
I have a pr for this if you are interested |
I would be very interested, provided of course it does not (unduly? !!) complicate the interface / steepen the learning curve for the average user. |
great. Could you add me to the repo collaborators or check it out at The new functionality/interface should be completely backwards compatible. If you like it, i can add tests and docs. |
I have added you to the list of repo collaborators. :-) I think it is a little complicated as it stands. Would it help to
Would you also mind providing some examples and docs? P.S. Do you use nested dict a lot and did you have motivating test cases? |
TDD? what's that?
I've been needing something like nested_dict for a while. I started working on something like it to allow dict-like access to lists or vice, versa, but got busy. I like your structure better anyway. |
I think you could make an argument that even the dict merge should be customizable. I have a use case where I have a dict d1 and I'd like to over-ride it with d2 when their keys overlap, but not inject any items of d2 that aren't already in d1. If we could over-ride dict combine policy then I could call d1 = {'a':1,'f':'default'} The combiner policy would be a bit more challenging in this case. Your thoughts? I would make this a separate PR though. |
The standard library defines what is meant by update for two dicts.
For other container types, there may be several options.
Currently on d1.update(d2) if the value is a list then d2's list over-writes d1's list.
I would like to have the option of specifying the behaviour for lists and sets.
For example, i would like the lists here to merge by appending
d1 = {'a':1,'f':[1,3]}
d2 = {'a':1,'f':[1,2]}
d1.update(d2) ->
{'a':1,'f':[1,3,1,2]}
Or i might prefer my lists to uniquely append
d1.update(d2) ->
{'a':1,'f':[1,3,2]}
Or as in this S.O. http://stackoverflow.com/questions/1319338/combining-two-lists-and-removing-duplicates-without-removing-duplicates-in-orig
This could be done if update took a strategies parameter, perhaps a dict mapping types to combiners.
strategies=[{'name': 'unique_extend_list', 'signature': ('list','list'): 'combiner': lambda: x,y: x + list(set(y) - set(x)) },]
And then modify the _recursive_update to handle the cases.
Have you considered something like this?
The text was updated successfully, but these errors were encountered: