-
Notifications
You must be signed in to change notification settings - Fork 14
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
add magic methods as seen in set() and elsewhere #21
Comments
Shall I submit a pr? Is this feature in line with the project's goals? |
Thank you for the bump. I appreciate it.
That'd be awesome. Binary operators like Before you wrangle your spade and break ground: to be explicit, which operators
Any others? |
Yes I was thinking of what else could be added.
Other operators could be added, but it's not clear to me how useful they might be:
The interesting thing here is that since dictionaries are limited to unique keys, if you wanted to remove/update/etc multiple values for the same key, you could do Also considering subset/superset semantics ( Another possible point for discussion is that set operators are useful for sets... which have no order. Are there other possible operators that could be added that would do useful things considering omdict ordering? What other "rich" objects exist in python-land that have order-aware operators? I prefer to avoid creating new semantics for these operators and instead re-use existing conventions, and only break from them where it makes sense for this use-case. To be explicit here are the methods to be added:
possibly add "regular" methods?
possibly right-hand operators?
I expect that some of these ( |
By the way, I realized afterwards that most of the previous post is incorrect, since obviously you can have multiple duplicate values per key.
however the order is not defined at the moment, I will try to stick to whatever default order is used in the project (remove first matching element or last). |
By default, the last item is removed. A la
The other big question is whether to remove all matching items or just the |
I really don't know, I would do whatever might be more useful for url manipulation purposes, but it's been a while since I've worked with them. Rethinking things, I might suggest the removal of all matching items. I may not know how many items of that type exist, but I may know that I only want 1 to be present, so I might do this: |
Add functionality such that
>>> omdict(a=1, b=2) |= {'a': 'hello world'}
fully merges/updates (
add
all members) the omdict>>> omdict([('a', 1), ('b', 2), ('a', 'hello world')])
and similar functionality for
|
but returns a new object instead.I suggest also then to use
>>> omdict(a=1, b=2) += {'a': 'hello world'}
to produce a more "regular" update
>>> omdict([('b', 2), ('a', 'hello world')])
and once again
+
produces a new object insteadnewer versions of python will have dictionary insertion order as default, but this is still useful in the case that order does not particularly matter, but then if it does these operations should obviously also work with OrderedDict and other omdict instances to preserve order.
The text was updated successfully, but these errors were encountered: