-
-
Notifications
You must be signed in to change notification settings - Fork 14.4k
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
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) <| attrs compare: concatMapStringAttrsSep "\n" (k: v: f k v) attrs So it is shorter, but it is also harder to change the processing pipeline. concatStringsSep "\n" <| unique <| mapAttrs (k: v: f k v) <| attrs Whereas 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) <| attrs Or 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
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 |
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 |
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 ofapptainer
andsingularity
packages. 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.overriding
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.