about summary refs log tree commit diff
path: root/yants.nix
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@google.com>2019-08-08T12·24+0100
committerVincent Ambo <tazjin@google.com>2019-08-28T13·36+0100
commit2e576e10ab2d75d586bdf82f1fa0369b0352ef3d (patch)
tree16760a1522114c1f78f04c84ffe5c5305734d9d5 /yants.nix
parent2acdbb500926e3a61f85269858efbda29d64d539 (diff)
refactor: Gain back a few more lines
Diffstat (limited to 'yants.nix')
-rw-r--r--yants.nix22
1 files changed, 8 insertions, 14 deletions
diff --git a/yants.nix b/yants.nix
index 8da43f6385fa..f803740660ec 100644
--- a/yants.nix
+++ b/yants.nix
@@ -25,23 +25,18 @@ with builtins; let
     "${n}" = t1: t2: typedef "${n}<${t1.name},${t2.name}>" (c t1 t2);
   };
 
-  ofType = t: x: isAttrs x && x ? "type" && x.type == t;
-
   typeSet = foldl' (s: t: s // (if t ? "name" then { "${t.name}" = t; } else t)) {};
 
-  # Struct checks performed:
-  #
-  # 1. All existing fields match their types
-  # 2. No non-optional fields are missing.
-  # 3. No unexpected fields are in the struct.
+  # Struct implementation. Checks that all fields match their declared
+  # types, no optional fields are missing and no unexpected fields
+  # occur in the struct.
   #
   # Anonymous structs are supported (e.g. for nesting) by omitting the
   # name.
   checkField = def: value: current: field:
-  let
-    fieldVal = if hasAttr field value then value."${field}" else null;
-    type = def."${field}";
-    checked = type.check fieldVal;
+  let fieldVal = if hasAttr field value then value."${field}" else null;
+      type = def."${field}";
+      checked = type.check fieldVal;
   in if checked then (current && true)
      else (throw "Field ${field} is of type ${typeOf fieldVal}, but expected ${type.name}");
 
@@ -64,9 +59,8 @@ with builtins; let
       else (throw "Expected '${self.name}'-struct, but ${toPretty value} is of type ${typeOf value}");
   };
 
-  struct = arg:
-  if isString arg then (struct' arg)
-  else (struct' "anonymous" arg);
+  struct = arg: if isString arg then (struct' arg)
+                else (struct' "anonymous" arg);
 in (typeSet [
   # Primitive types
   (typedef "any" (_: true))