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.
server/nix/lib/lists.nix

43 lines
982 B
Nix

{ lib, ... }@flakeArg:
let
inherit (builtins)
deepSeq
foldl'
groupBy
mapAttrs
;
inherit (lib.lists) singleton;
inherit (lib.trivial) flip pipe;
in
{
groupByMult =
groupers:
# TODO (maybe) make more efficient by building up grouping function from right
# from left
# 0= (x: x) vals
# 1= groupBy values[0] <0>
# 2= mapAttrs (_: groupBy values[1]) <1>
# 3= mapAttrs (_: mapAttrs (_: groupBy values[2])) <2>
# from right
# 1= (groupBy values[0])
# 2= ...
let
nul = {
mapper = x: x;
result = [ ];
};
op =
{ mapper, result }:
grouper: {
mapper = fun: mapAttrs (_: mapper fun);
result = result ++ singleton (mapper grouper);
};
list = map groupBy groupers;
pipeList = (foldl' op nul list).result;
in
# catch errors while building groupers before values are passed through
deepSeq pipeList (flip pipe pipeList);
}