-
-
Notifications
You must be signed in to change notification settings - Fork 14.6k
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
lib: add concatMapAttrsToList #369146
base: master
Are you sure you want to change the base?
lib: add concatMapAttrsToList #369146
Conversation
This is the concatMap counterpart to mapAttrsToList. Co-authored-by: Dusk Banks <[email protected]>
1795158
to
b9bcf7c
Compare
# FIXME | ||
concatMapAttrsToList :: (String -> a -> b) -> AttrSet -> [b] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am very confused by the type syntax, I'll need help to get this right (this is currently a copy-paste of mapAttrsToList
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This, right?
# FIXME | |
concatMapAttrsToList :: (String -> a -> b) -> AttrSet -> [b] | |
# FIXME | |
concatMapAttrsToList :: (String -> a -> [b]) -> AttrSet -> [b] |
|
||
::: | ||
*/ | ||
concatMapAttrsToList = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Naming is hard. concatMapAttrs
is taken by what should be mergeMapAttrs
. I've also considered mapAttrsToConcatList
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this is, I think, f: attrs: concatLists (attrValues (mapAttrs f attrs))
?
Should we be aiming for giving a name to all combinations of builtins
primitives like this below some size? If not, what's the argument for why this combination gets special treatment? (I'm not presupposing that there isn't one; I'd just like to understand what you have in mind.)
# FIXME | ||
concatMapAttrsToList :: (String -> a -> b) -> AttrSet -> [b] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This, right?
# FIXME | |
concatMapAttrsToList :: (String -> a -> b) -> AttrSet -> [b] | |
# FIXME | |
concatMapAttrsToList :: (String -> a -> [b]) -> AttrSet -> [b] |
I am completely unfamiliar with the underlying implementation, but I think this would allocate an extra attrset and a list? If so, this defeats the point here, see below.
So the rationale is efficient map-filter over an attrset into a list (it's probably useful for other things, but that's the main use-case). This takes advantage of empty and one-element lists being stored efficiently, while I'd love to call this |
Efficiency, okay. Yes, this does save an allocation relative to using Do you expect to use this somewhere that is called enough times or on a large enough attrset for that to make any sort of noticeable difference? There are a few places in Nixpkgs where the (The number of bytes used by lists, in my benchmark of evaluating my local configuration, went down from 23,018,728 to 23,015,560. Count of concatenations went down from 439,757 to 439,513. Time elapsed for
|
This is the concatMap counterpart to mapAttrsToList.
Usage example: nix-community/home-manager#6229
cc @bb010g
Things done
nix.conf
? (See Nix manual)sandbox = relaxed
sandbox = true
nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD"
. Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/
)Add a 👍 reaction to pull requests you find important.