Add a monoid to lib that merges objects together
This commit is contained in:
parent
e9e0b0dc2a
commit
977595f7e8
1 changed files with 27 additions and 0 deletions
|
|
@ -1,2 +1,29 @@
|
||||||
lib: {
|
lib: {
|
||||||
|
hylonix = {
|
||||||
|
recursiveMerge =
|
||||||
|
let
|
||||||
|
f =
|
||||||
|
x: y:
|
||||||
|
if y == null then
|
||||||
|
x
|
||||||
|
else if builtins.typeOf x != builtins.typeOf y then
|
||||||
|
y
|
||||||
|
else if builtins.typeOf x == "set" then
|
||||||
|
builtins.listToAttrs (
|
||||||
|
builtins.map (name: {
|
||||||
|
inherit name;
|
||||||
|
value = f (x.${name} or null) (y.${name} or null);
|
||||||
|
}) (builtins.attrNames y ++ builtins.attrNames x)
|
||||||
|
)
|
||||||
|
else if builtins.typeOf x == "list" then
|
||||||
|
x ++ y
|
||||||
|
else
|
||||||
|
y;
|
||||||
|
in
|
||||||
|
f;
|
||||||
|
|
||||||
|
recursiveMergeAll = builtins.foldl' lib.hylonix.recursiveMerge null;
|
||||||
|
};
|
||||||
|
|
||||||
|
inherit (lib.hylonix) recursiveMerge recursiveMergeAll;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue