You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

11 lines
341 B
Nix

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]
}