-
-
Notifications
You must be signed in to change notification settings - Fork 17.8k
lib.strings.concatMapAttrsStringSep: init #330010
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.strings.concatMapAttrsStringSep: init #330010
Conversation
|
Result of 1 package blacklisted:
|
|
BrainstormingI'm trying to think what's the problem we're generally trying to solve. I think it's
(1) could be solved with the pipe operator reduce.fromAttrs (reduce.concatStrings) attrs
reduce.mapAttrs (reduce.concatSep "-") (k: v: f k v) attrs
reduce.fromList reduce.concatStrings [ "a;" "b;" ]
reduce.fromList reduce.lines [ "a" "b" ]
reduce.map reduces.lines (x: "${x};") [ "a" "b" ]The However, this is not actually more expressive than a pipe like this attrs
|> mapAttrs (k: v: f k v)
|> concatStringsSep "\n"or potentially concatStringsSep "\n" <| mapAttrs (k: v: f k v) <| attrscompare: concatMapStringAttrsSep "\n" (k: v: f k v) attrsSo it is shorter, but it is also harder to change the processing pipeline. concatStringsSep "\n" <| unique <| mapAttrs (k: v: f k v) <| attrsWhereas with Of course we don't quite have pipe operators yet.
So until we have that, we need parentheses ConclusionNot a big fan, but I'd like to move forward with this in the meanwhile, I will probably use it, but eventually I'd like to get rid of it. (At least in terms of actual use; not sure about deprecation. I'd prefer for a linter to suggest it, rather than spewing out warnings) |
@roberth Thank you for sharing insight into the structural problem of adding all these composite functions. Providing reusable and composable parts is indeed better than pouring all the combinations of
I didn't find explicit documentation about the lifecycle of each Nix version and the backport policy, and Nixpkgs's
As for the current standard library, concatStringsSep "\n" (attrValues (mapAttrs (k: v: f k v) attrs))With the pipe operator, it would be concatStringsSep "\n" <| attrValues <| mapAttrs (k: v: f k v) <| attrsOr the other direction. I'll restructure the |
|
@fricklerhandwerk I just remembered that I need to add double stars at the beginning of the comment block ( |
ee1293c to
dcb7e03
Compare
infinisil
left a comment
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.
Needs a test, but other than that I'm totally in favor of having this!
@roberth Let's keep the model of diverging, then converging in mind. I think we are in the diverging phase with a lot of lib, where we don't have good answers to everything, so it's fine to experiment a bit, even in the stable namespace (but only with long, unambiguous identifiers!). Though having an experimental lib would be great too for this, but that's a future topic :)
Glad you like it! There is a test inside lib/tests/misc.nix. |
52c541b to
5e629d8
Compare
|
I renamed it I noticed that |
infinisil
left a comment
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 think this is good other than the one comment I left!
5e629d8 to
8ebce1f
Compare
Use concatMapAttrsStringSep helper function from the standard library instead of the locally-improvised one.
8ebce1f to
226b370
Compare
|
@infinisil Thank you for your approval. I rebased the feature branch to resolve conflicts, adopted the The |
|
Shouldn't this have been named |
|
@infinisil Do you think we should add the extra "s"? Initial naming: #330010 (comment) |
|
Update: Just realized that this was merged a year ago. I had thought it was just merged due to the notification. There is no compelling reason to rename. I apologise for the noise caused by pinging. |
Description of changes
This pull request introduces
lib.concatMapAttrsStringSep, the attribute set version oflib.concatMapAttrsStringSet. This function is initially defined locally in the Nix expression ofapptainerandsingularitypackages. It increases the readability of attribute-set-to-string expressions.Before
or
After
Cc:
@infinisil for the new library function
@roberth for the restructuring of
tests.overridingThings done
nix.conf? (See Nix manual)sandbox = relaxedsandbox = truenix-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.