-
Notifications
You must be signed in to change notification settings - Fork 141
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 del_in()
to colls.py for symmetry and completeness
#102
Comments
There are a couple of issues with this:
So we come to a combinatoric explosion, which is traditionally solved with composition. In this case we can pass things to update_in({'a': {'b': 0, 'c': 1}}, ['a'], rpartial(omit, {'c'}))
# if we expect path may not always be present
update_in(coll, path, rpartial(omit, keys), default={})
# several things to omit
update_in(coll, path, rpartial(omit, {'c', 'd'}))
# whitelist keys on path
update_in(coll, path, rpartial(project, {'a', 'b'}))
# ... If you happen to do any particular of these operations a lot you may write a one-line helper. I am not sure that one should be included into funcy just yet. |
Wow, I think I just didn't spend enough time toying around with
So, loosely speaking, we have Having the complete set of basic |
Ok, if you frame it as adding |
omit_in
function in colls.py to omit key-value pairs in deeply nested collectionsdel_in()
to colls.py for symmetry and completeness
EDIT by @Suor. I changed
omit_in
todel_in()
in the title, since it matches better with a particular need - see discussion. The text below stays as is and thus still will refer to the proposed function asomit_in
.I recently had to add another function to the family of
get_in
,update_in
andset_in
from thefuncy.colls
module. The goal here is to omit the key-value pair atpath
. I think that the implementation and docstring speak by themselves:This is almost like
omit({'a': 0, 'b': 1}, 'a')
, but it also works with deeppath
s.If you are interested in adding this to Funcy, I would gladly submit a PR 😄
And, if that is the case, some points I'd like to ask you what exceptions should be raised in case: (1)
path
is empty, so that*path, key = path
fails withValueError: not enough values to unpack (expected at least 1, got 0)
; and (2)path
is not a valid path for the collectioncoll
(see 3rd example in the docstring).The text was updated successfully, but these errors were encountered: