keepAttrs -> getAttrs
This commit is contained in:
parent
2236fec907
commit
44fe044655
|
@ -11,11 +11,8 @@
|
||||||
inherit util;
|
inherit util;
|
||||||
|
|
||||||
genAttrs = import ./src/genAttrs.nix lib;
|
genAttrs = import ./src/genAttrs.nix lib;
|
||||||
|
getAttrs = import ./src/getAttrs.nix lib;
|
||||||
subtractLists = import ./src/subtractLists.nix lib;
|
subtractLists = import ./src/subtractLists.nix lib;
|
||||||
unique = import ./src/unique.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;
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
|
@ -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" ];
|
|
||||||
}
|
|
Loading…
Reference in New Issue