mirror of
https://github.com/mjallen18/snowfall-lib.git
synced 2026-04-18 09:05:58 -05:00
refactor: reduce code duplication with merge-with-aliases helper
Add merge-with-aliases function to attrs module and use it across checks, modules, packages, shells, and templates to eliminate repeated alias merging logic. Also optimize get-libs by replacing filter+map with a fold operation.
This commit is contained in:
@@ -97,12 +97,15 @@ rec {
|
||||
#@ Attrs -> Attrs
|
||||
get-libs =
|
||||
attrs:
|
||||
let
|
||||
# @PERF(jakehamilton): Replace filter+map with a fold.
|
||||
attrs-with-libs = filterAttrs (name: value: builtins.isAttrs (value.lib or null)) attrs;
|
||||
libs = builtins.mapAttrs (name: input: input.lib) attrs-with-libs;
|
||||
in
|
||||
libs;
|
||||
foldl
|
||||
(acc: name:
|
||||
let value = attrs.${name}; in
|
||||
if builtins.isAttrs (value.lib or null)
|
||||
then acc // { ${name} = value.lib; }
|
||||
else acc
|
||||
)
|
||||
{ }
|
||||
(builtins.attrNames attrs);
|
||||
};
|
||||
|
||||
mkFlake =
|
||||
|
||||
Reference in New Issue
Block a user