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: introduce foreach
, combined
and combined map
idioms
#57091
Conversation
This PR adds `foreach` and `combined` functions. They are repainted versions of following standard lib functions: - `foreach == flip map` - `foreach == flip mapAttrs` when applied to attrset - `combined == concatString` - `combined "sep" == concatStringSep "sep"` - `combined map == flip concatMapStrings` - `combined "sep" map == flip (concatMapStringsSep "sep")` The idea behind this rename is to encourage flipped usage of functions in templaters and other script generators. Flipped version are often easier to read. They are also more consistent with existing usage of `optional`, `optionalAttrs`, `mkIf` in sense that *usually* first argument is shorter (syntatically) than second.
I'm okay with the |
@infinisil I found that most unreadable code is in script generators. And those use So yeah, all 4 forms do have separate names, and we can live with that... except that it still looks ugly to me. Maybe I should change description, to make it more user-friendly:
I can split it into two functions |
@danbst Care to push this ahead with just |
@aanderse done #64723. I've removed varargs behavior to keep it simple. Overall, I still love my And while we are here, the support from Nix for python-styled generators would also be great. NixOS/nix#2543 |
Closing this now, maybe another time. |
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: |
This PR adds
foreach
andcombined
functions. They are repaintedversions of following standard lib functions:
foreach == flip map
foreach == flip mapAttrs
when applied to attrsetcombined == concatStrings
combined "sep" == concatStringsSep "sep"
combined map == flip concatMapStrings
combined "sep" map == flip (concatMapStringsSep "sep")
The idea behind this rename is to encourage flipped usage of functions
in templaters and other script generators.
Flipped version are often easier to read. They are also more consistent with
existing usage of
optional
,optionalAttrs
,mkIf
in sense thatusually first argument is shorter (syntatically) than second.
I rewrote two files in Nixos to show how these new functions should be used.
Things done
sandbox
innix.conf
on non-NixOS)nix-shell -p nox --run "nox-review wip"
./result/bin/
)nix path-info -S
before and after)