html.nix/utils.nix

39 lines
933 B
Nix
Raw Normal View History

let
2021-05-15 19:42:16 +03:00
inherit (builtins) isAttrs isList map any concatMap concatStringsSep listToAttrs genList;
mapAttrsToList = f: attrs: map (name: f name attrs.${name}) (builtins.attrNames attrs);
in
2022-07-30 12:42:09 +03:00
{
inherit mapAttrsToList;
2022-07-30 12:42:09 +03:00
recursiveAttrPaths = set: let
flattenIfHasList = x:
if (isList x) && (any isList x)
then concatMap flattenIfHasList x
2022-07-30 12:42:09 +03:00
else [x];
2022-07-30 12:42:09 +03:00
recurse = path: set: let
g = name: value:
if isAttrs value
then recurse (path ++ [name]) value
else path ++ [name];
in
mapAttrsToList g set;
in
2022-07-30 12:42:09 +03:00
flattenIfHasList (recurse [] set);
2022-07-30 12:42:09 +03:00
concatStrings = concatStringsSep "";
genAttrs = f: names:
listToAttrs (map (n: {
name = n;
value = f n;
})
names);
2021-05-15 19:42:16 +03:00
2022-07-30 12:42:09 +03:00
range = first: last:
if first > last
then []
else genList (n: first + n) (last - first + 1);
}
// builtins