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

doc: listToAttrs: document repeated keys #7381

Merged
merged 3 commits into from
Dec 2, 2022

Conversation

aakropotkin
Copy link
Contributor

@aakropotkin aakropotkin commented Dec 1, 2022

Previously I had thought this was implemented as the first example below ( I was wrong ):

# WRONG
listToAttrs = attrs:
  builtins.foldl' ( acc: key: acc // { ${key} = attrs.${key}; } ) {}
                  ( builtins.attrNames attrs );
# RIGHT
listToAttrs = attrs:
  builtins.foldl' ( acc: key: { ${key} = attrs.${key}; } // acc ) {}
                  ( builtins.attrNames attrs );

I was browsing the primops.cc sources and bumped into an inline comment that mentioned that it was actually the opposite behavior: listToAttrs preserves the "first instance" of a key.

This change adds a note to the docstring, and extends the existing example to make the behavior clear to users.

Copy link
Contributor

@fricklerhandwerk fricklerhandwerk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great catch, thank you!

src/libexpr/primops.cc Outdated Show resolved Hide resolved
@fricklerhandwerk fricklerhandwerk merged commit 0ce5742 into NixOS:master Dec 2, 2022
@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/2022-12-02-nix-team-meeting-minutes-13/23731/1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

3 participants