Skip to content

Commit

Permalink
lib: refactor filterAttrs
Browse files Browse the repository at this point in the history
`filter` is a primop which is designed for this task, and it saves
the allocation of some singleton lists here.
  • Loading branch information
roberth committed Oct 31, 2024
1 parent 83e1488 commit 1de8e07
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/attrsets.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ let
inherit (builtins) head length;
inherit (lib.trivial) isInOldestRelease mergeAttrs warn warnIf;
inherit (lib.strings) concatStringsSep concatMapStringsSep escapeNixIdentifier sanitizeDerivationName;
inherit (lib.lists) foldr foldl' concatMap elemAt all partition groupBy take foldl;
inherit (lib.lists) filter foldr foldl' concatMap elemAt all partition groupBy take foldl;
in

rec {
Expand Down Expand Up @@ -644,7 +644,7 @@ rec {
filterAttrs =
pred:
set:
removeAttrs set (concatMap (name: if pred name set.${name} then [ ] else [ name ]) (attrNames set));
removeAttrs set (filter (name: ! pred name set.${name}) (attrNames set));

/**
Filter an attribute set recursively by removing all attributes for
Expand Down

0 comments on commit 1de8e07

Please sign in to comment.