lix/doc/manual/utils.nix

16 lines
427 B
Nix
Raw Normal View History

2020-09-16 14:55:24 +02:00
with builtins;
2021-01-25 18:19:32 +01:00
rec {
2020-09-16 14:55:24 +02:00
splitLines = s: filter (x: !isList x) (split "\n" s);
concatStrings = concatStringsSep "";
2021-01-25 18:19:32 +01:00
# FIXME: O(n^2)
unique = foldl' (acc: e: if elem e acc then acc else acc ++ [ e ]) [];
nameValuePair = name: value: { inherit name value; };
filterAttrs = pred: set:
listToAttrs (concatMap (name: let v = set.${name}; in if pred name v then [(nameValuePair name v)] else []) (attrNames set));
2020-09-16 14:55:24 +02:00
}