keepAttrs -> getAttrs

This commit is contained in:
Oystein Kristoffer Tveit 2024-09-27 22:22:16 +02:00
parent 2236fec907
commit 44fe044655
Signed by: oysteikt
GPG Key ID: 9F2F7D8250F35146
3 changed files with 13 additions and 14 deletions

View File

@ -11,11 +11,8 @@
inherit util;
genAttrs = import ./src/genAttrs.nix lib;
getAttrs = import ./src/getAttrs.nix lib;
subtractLists = import ./src/subtractLists.nix lib;
unique = import ./src/unique.nix lib;
# This doesn't actually exist, but I've seen it's definition being used
# a few places.
keepAttrs = import ./src/keepAttrs.nix lib;
};
}

12
src/getAttrs.nix Normal file
View File

@ -0,0 +1,12 @@
lib:
let
getAttrsOld = names: attrs: lib.genAttrs names (name: attrs.${name});
getAttrsNew1 = names: attrs: lib.filterAttrs (n: _: builtins.elem n names) attrs;
getAttrsNew2 = names: attrs: builtins.intersectAttrs (lib.genAttrs names (_: null)) attrs;
bigdata = lib.genAttrs (lib.imap0 (i: _: toString i) (lib.replicate 999999 null)) (_: null);
in {
old = getAttrsOld [ "123" "456" ] bigdata;
new1 = getAttrsNew1 [ "123" "456" ] bigdata;
new2 = getAttrsNew2 [ "123" "456" ] bigdata;
}

View File

@ -1,10 +0,0 @@
lib:
let
keepAttrsOld = attrs: names: lib.filterAttrs (n: _: builtins.elem n names) attrs;
keepAttrsNew = attrs: names: builtins.intersectAttrs (lib.genAttrs names (_: null)) attrs;
bigdata = lib.genAttrs (lib.imap0 (i: _: toString i) (lib.replicate 999999 null)) (_: null);
in {
old = keepAttrsOld bigdata [ "123" "456" ];
new = keepAttrsNew bigdata [ "123" "456" ];
}