From 07f95570063561c0f9d4f7f6f1c44368c1eab14d Mon Sep 17 00:00:00 2001 From: NaiJi Date: Fri, 29 Apr 2022 04:11:45 +0000 Subject: [PATCH] Add '33.nix' --- 33.nix | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 33.nix diff --git a/33.nix b/33.nix new file mode 100644 index 0000000..9b9a752 --- /dev/null +++ b/33.nix @@ -0,0 +1,11 @@ +with import { }; +let + list = [["a"] ["b"] ["c"]]; + + attrList = [{a = 1;} {b = 0;} {a = 2;}]; + catAttrs = atr: l: lib.fold (val: _l: if (builtins.hasAttr atr val) then [ (val.${atr}) ] ++ _l else _l) [] l; +in +rec { + example = builtins.concatLists list; #is [ "a" "b" "c" ] + result = catAttrs "a" attrList; #should be [1 2] +} \ No newline at end of file