fix: mergeStruct family of functions
This commit is contained in:
parent
90d7aa59ad
commit
6ab22a0017
1 changed files with 22 additions and 18 deletions
|
|
@ -54,26 +54,30 @@ with nib.types; rec {
|
||||||
inherit path;
|
inherit path;
|
||||||
});
|
});
|
||||||
|
|
||||||
# check is a function taking two structs
|
mergeStructs' = f: cond: S: T:
|
||||||
# and returning a result monad.
|
mapAttrsRecursiveCond
|
||||||
mergeStruct' = check: template: S: let
|
cond
|
||||||
R = check template S;
|
(path: valueS: let
|
||||||
in
|
valueT = attrValueAt T path;
|
||||||
errOr ({...}:
|
in
|
||||||
Ok (
|
unwrapSome valueT (_: f valueS))
|
||||||
mapAttrsRecursive (
|
S;
|
||||||
path: value: let
|
|
||||||
valueS = attrValueAt S path;
|
|
||||||
in
|
|
||||||
if valueS != null
|
|
||||||
then valueS
|
|
||||||
else value
|
|
||||||
)
|
|
||||||
template
|
|
||||||
))
|
|
||||||
R;
|
|
||||||
|
|
||||||
# mergeStruct ensures no properties are evaluated (entirely lazy)
|
# mergeStruct ensures no properties are evaluated (entirely lazy)
|
||||||
|
mergeStructs = mergeStruct (x: x);
|
||||||
|
|
||||||
|
# given a template struct, and the struct to parse
|
||||||
|
parseStructFor =
|
||||||
|
mergeStructs'
|
||||||
|
(leaf: !isTerminal leaf)
|
||||||
|
(value:
|
||||||
|
if isTerminal value
|
||||||
|
then unwrapTerminal value
|
||||||
|
else valueS);
|
||||||
|
|
||||||
|
# TODO: Define:
|
||||||
|
# TODO: throwUnreachable = throw "Unreachable code was evaluated..";
|
||||||
|
# TODO: abortUnreachable = abort "Unreachable code was evaluated...";
|
||||||
mergeStruct = mergeStruct' (_: _: Ok');
|
mergeStruct = mergeStruct' (_: _: Ok');
|
||||||
|
|
||||||
# mergeTypedPartialStruct must evaluate properties (not lazy)
|
# mergeTypedPartialStruct must evaluate properties (not lazy)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue