diff --git a/flake.nix b/flake.nix index 39fce60..123eed6 100644 --- a/flake.nix +++ b/flake.nix @@ -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; }; } diff --git a/src/getAttrs.nix b/src/getAttrs.nix new file mode 100644 index 0000000..57dc1af --- /dev/null +++ b/src/getAttrs.nix @@ -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; +} diff --git a/src/keepAttrs.nix b/src/keepAttrs.nix deleted file mode 100644 index e71623c..0000000 --- a/src/keepAttrs.nix +++ /dev/null @@ -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" ]; -}