use with builtins nib.types
This commit is contained in:
parent
ead4d37ca7
commit
600cac3ce3
6 changed files with 36 additions and 31 deletions
|
|
@ -1,10 +1,11 @@
|
|||
{nib, ...} @ args: let
|
||||
struct = import ./struct.nix args;
|
||||
in
|
||||
nib.types.mergeAttrsList [
|
||||
# submodule is included directly to this module (ie self.myFunc)
|
||||
struct
|
||||
with nib.types;
|
||||
mergeAttrsList [
|
||||
# submodule is included directly to this module (ie self.myFunc)
|
||||
struct
|
||||
|
||||
# submodule content is accessible first by submodule name
|
||||
# then by the name of the content (ie self.submodule.myFunc)
|
||||
]
|
||||
# submodule content is accessible first by submodule name
|
||||
# then by the name of the content (ie self.submodule.myFunc)
|
||||
]
|
||||
|
|
|
|||
|
|
@ -1,23 +1,23 @@
|
|||
{nib, ...}:
|
||||
with builtins nib.types; rec {
|
||||
cmpStructErr' = errBadKeys: errBadValues: path: S: T:
|
||||
if builtins.isAttrs S && builtins.isAttrs T
|
||||
if isAttrs S && isAttrs T
|
||||
then let
|
||||
keysS = builtins.attrNames S;
|
||||
keysT = builtins.attrNames T;
|
||||
keysS = attrNames S;
|
||||
keysT = attrNames T;
|
||||
in
|
||||
# ensure all key names match, then recurse
|
||||
if !(keysS == keysT)
|
||||
then errBadKeys path keysS keysT
|
||||
else
|
||||
(firstErr
|
||||
(builtins.map
|
||||
(map
|
||||
(k: cmpStructErr' errBadKeys errBadValues (path ++ [k]) (keysS.${k}) (keysT.${k}))
|
||||
keysS))
|
||||
else
|
||||
# terminating leaf in recursion tree reached
|
||||
# ensure values' types match
|
||||
(builtins.typeOf S == builtins.typeOf T)
|
||||
(typeOf S == typeOf T)
|
||||
|| errBadValues path S T;
|
||||
|
||||
cmpStructErr = errBadKeys: errBadValues: cmpStructErr' errBadKeys errBadValues [];
|
||||
|
|
@ -60,9 +60,9 @@ with builtins nib.types; rec {
|
|||
in
|
||||
errOr ({...}:
|
||||
Ok (
|
||||
attrs.mapAttrsRecursive (
|
||||
mapAttrsRecursive (
|
||||
path: value: let
|
||||
valueS = attrs.attrValueAt S path;
|
||||
valueS = attrValueAt S path;
|
||||
in
|
||||
if valueS != null
|
||||
then valueS
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue