-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
removeAttrs
: allow removals to be specified as attrset, and conversely for intersectAttrs
#9050
Comments
Not a fan of this, because:
Imo the path forward is to leave the builtins alone and instead implement better functions in
Such that |
True, but implemented in C++ would perform slightly better.
Should be somewhat expected in a lazy language, but I'm biased; I'm rather comfortable with laziness. That's rare.
We never use "keys". It's always something like attributes, attrNames, attrs.
Conversions to list tend to allocate more, and the algorithms can't take advantage of the list's properties, because it has basically none. |
The performance argument is a really good one. Here's another thought: These two operations (selecting attributes and removing attributes) can probably be done more efficiently together (which is often also what you actually need). So how about something like this: builtins.diffAttrs { a = 0; b = 0; } { b = 1; c = 1; }
-> {
only.left = { a = 0; };
both.left = { b = 0; };
both.right = { b = 1; };
only.right = { c = 1; };
} This does cost extra attribute allocations (though this could be optimised with an idea like #7676). However this cost is constant, compared to the cost of having to run both |
That's a lot like a Another option is combineAttrs (name: left: left) (name: left: right: left + right) (name: right: right) { a = 0; b = 1; } { b = 10; c = 20; }
{ a = 0; b = 11; c = 20; } or if you want more flexibility in the style of mergeZipAttrs (name: left: { ${name} = left; }) (name: left: right: { ${name} = left + right; ${name}-left = left; ${name}-right = right; }) (name: right: { ${name} = right; }) { a = 0; b = 1; } { b = 10; c = 20; }
{ a = 0; b = 11; c = 20; b-left = 1; b-right = 10; } Idk what's better. |
Is your feature request related to a problem? Please describe.
I'd expect the following to work,
but instead I have to write this:
This is arbitrary. Let's just make it work.
Describe the solution you'd like
The second argument of
removeAttrs
is allowed to be an attrset where the values are ignored.The first argument of
intersectAttrs
is allowed to be a list where the items are interpreted as attribute names.Describe alternatives you've considered
lib
.Additional context
Priorities
Add 👍 to issues you find important.
The text was updated successfully, but these errors were encountered: