Add '33.nix'

This commit is contained in:
NaiJi ✨ 2022-04-29 04:11:45 +00:00
parent 8c8f645473
commit 07f9557006
1 changed files with 11 additions and 0 deletions

11
33.nix Normal file
View File

@ -0,0 +1,11 @@
with import <nixpkgs> { };
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]
}