lib/modules.nix: small eval optimization (foldl' + foldl' + attrNames -> foldl' + mapAttrs)
This commit is contained in:
parent
f32987d451
commit
aa2e63ce5e
|
@ -214,23 +214,25 @@ rec {
|
||||||
qux = [ "module.hidden=baz,value=bar" "module.hidden=fli,value=gne" ];
|
qux = [ "module.hidden=baz,value=bar" "module.hidden=fli,value=gne" ];
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
byName = attr: f: modules: foldl' (acc: module:
|
byName = attr: f: modules:
|
||||||
foldl' (inner: name:
|
foldl' (acc: module:
|
||||||
inner // { ${name} = (acc.${name} or []) ++ (f module module.${attr}.${name}); }
|
acc // (mapAttrs (n: v:
|
||||||
) acc (attrNames module.${attr})
|
(acc.${n} or []) ++ f module v
|
||||||
|
) module.${attr}
|
||||||
|
)
|
||||||
) {} modules;
|
) {} modules;
|
||||||
# an attrset 'name' => list of submodules that declare ‘name’.
|
# an attrset 'name' => list of submodules that declare ‘name’.
|
||||||
declsByName = byName "options"
|
declsByName = byName "options" (module: option:
|
||||||
(module: option: [{ inherit (module) file; options = option; }])
|
[{ inherit (module) file; options = option; }]
|
||||||
options;
|
) options;
|
||||||
# an attrset 'name' => list of submodules that define ‘name’.
|
# an attrset 'name' => list of submodules that define ‘name’.
|
||||||
defnsByName = byName "config" (module: value:
|
defnsByName = byName "config" (module: value:
|
||||||
map (config: { inherit (module) file; inherit config; }) (pushDownProperties value)
|
map (config: { inherit (module) file; inherit config; }) (pushDownProperties value)
|
||||||
) configs;
|
) configs;
|
||||||
# extract the definitions for each loc
|
# extract the definitions for each loc
|
||||||
defnsByName' = byName "config"
|
defnsByName' = byName "config" (module: value:
|
||||||
(module: value: [{ inherit (module) file; inherit value; }])
|
[{ inherit (module) file; inherit value; }]
|
||||||
configs;
|
) configs;
|
||||||
in
|
in
|
||||||
(flip mapAttrs declsByName (name: decls:
|
(flip mapAttrs declsByName (name: decls:
|
||||||
# We're descending into attribute ‘name’.
|
# We're descending into attribute ‘name’.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user