Skip to content
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

Implement builtins.zipAttrsWith #1055

Open
Tracked by #1030
Anton-Latukha opened this issue Feb 9, 2022 · 0 comments
Open
Tracked by #1030

Implement builtins.zipAttrsWith #1055

Anton-Latukha opened this issue Feb 9, 2022 · 0 comments

Comments

@Anton-Latukha
Copy link
Collaborator

Anton-Latukha commented Feb 9, 2022

A port of lib function added in Nix 2.6.
Nixpkgs lib/attrsets.nix mentions:

{
  /* Merge sets of attributes and use the function f to merge attributes
     values.

     Example:
       zipAttrsWithNames ["a"] (name: vs: vs) [{a = "x";} {a = "y"; b = "z";}]
       => { a = ["x" "y"]; }
  */
  zipAttrsWithNames = names: f: sets:
    listToAttrs (map (name: {
      inherit name;
      value = f name (catAttrs name sets);
    }) names);

  /* Implementation note: Common names appear multiple times in the list of
     names, hopefully this does not affect the system because the maximal
     laziness avoid computing twice the same expression and listToAttrs does
     not care about duplicated attribute names.

     Example:
       zipAttrsWith (name: values: values) [{a = "x";} {a = "y"; b = "z";}]
       => { a = ["x" "y"]; b = ["z"] }
  */
  zipAttrsWith =
    builtins.zipAttrsWith or (f: sets: zipAttrsWithNames (concatMap attrNames sets) f sets);
}
@Anton-Latukha Anton-Latukha mentioned this issue Feb 9, 2022
13 tasks
@Anton-Latukha Anton-Latukha changed the title Implement builtins.zipAttrsWith Implement builtins.zipAttrsWith Feb 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant