fix oversight in struct cmp/merge implementation
This commit is contained in:
parent
623c53995c
commit
00bc247a55
1 changed files with 25 additions and 23 deletions
|
|
@ -48,25 +48,7 @@
|
||||||
inherit path;
|
inherit path;
|
||||||
});
|
});
|
||||||
|
|
||||||
# check is a function taking two structs
|
cmpTypedPartialStruct =
|
||||||
# and returning a result monad.
|
|
||||||
mergeStruct' = check: template: S: let
|
|
||||||
res = check template S;
|
|
||||||
in
|
|
||||||
result.errOr res ({...}:
|
|
||||||
attrs.mapAttrsRecursive (
|
|
||||||
path: value: let
|
|
||||||
valueS = attrs.attrValueAt S path;
|
|
||||||
in
|
|
||||||
if valueS != null
|
|
||||||
then valueS
|
|
||||||
else value
|
|
||||||
)
|
|
||||||
template);
|
|
||||||
|
|
||||||
mergeStruct = mergeStruct' (S: T: result.Ok "ok");
|
|
||||||
|
|
||||||
mergeTypedStruct = mergeStruct' (
|
|
||||||
cmpStructErr
|
cmpStructErr
|
||||||
(path: keysS: keysT:
|
(path: keysS: keysT:
|
||||||
result.Ok "ok")
|
result.Ok "ok")
|
||||||
|
|
@ -74,10 +56,30 @@
|
||||||
result.Err {
|
result.Err {
|
||||||
reason = "values";
|
reason = "values";
|
||||||
inherit path;
|
inherit path;
|
||||||
})
|
});
|
||||||
);
|
|
||||||
|
|
||||||
mergeStructStrict = mergeStruct' cmpStruct;
|
# check is a function taking two structs
|
||||||
|
# and returning a result monad.
|
||||||
|
mergeStruct' = check: template: S: let
|
||||||
|
res = check template S;
|
||||||
|
in
|
||||||
|
result.errOr res ({...}:
|
||||||
|
result.Ok (
|
||||||
|
attrs.mapAttrsRecursive (
|
||||||
|
path: value: let
|
||||||
|
valueS = attrs.attrValueAt S path;
|
||||||
|
in
|
||||||
|
if valueS != null
|
||||||
|
then valueS
|
||||||
|
else value
|
||||||
|
)
|
||||||
|
template
|
||||||
|
));
|
||||||
|
|
||||||
mergeTypedStructStrict = mergeStruct' cmpTypedStruct;
|
# mergeStruct ensures no properties are evaluated (entirely lazy)
|
||||||
|
mergeStruct = mergeStruct' (S: T: result.Ok "ok");
|
||||||
|
|
||||||
|
# mergeTypedPartialStruct must evaluate properties (not lazy)
|
||||||
|
# for lazy evaluation use mergeStruct instead!
|
||||||
|
mergeTypedPartialStruct = mergeStruct' cmpTypedPartialStruct;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue