html.nix/utils.nix

37 lines
919 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
{
inherit mapAttrsToList;
recursiveAttrPaths = set:
let
flattenIfHasList = x:
if (isList x) && (any isList x)
then concatMap flattenIfHasList x
else [ x ];
recurse = path: set:
let
g =
name: value:
if isAttrs value
then recurse (path ++ [ name ]) value
else path ++ [ name ];
in
mapAttrsToList g set;
in
flattenIfHasList (recurse [ ] set);
concatStrings = concatStringsSep "";
genAttrs = f: names: listToAttrs (map (n: { name = n; value = (f n); }) names);
2021-05-15 19:42:16 +03:00
range = first: last:
if first > last then
[ ]
else
genList (n: first + n) (last - first + 1);
} // builtins