2 # Simple internal type checks for meta.
3 # This file is not a stable interface and may be changed arbitrarily.
5 # TODO: add a method to the module system types
6 # see https://github.com/NixOS/nixpkgs/pull/273935#issuecomment-1854173100
21 isTypeDef = t: isAttrs t && t ? name && isString t.name && t ? verify && isFunction t.verify;
29 str = self.string; # Type alias
68 name = "attrsOf<${t.name}>";
70 # attrsOf<any> can be optimised to just isAttrs
71 if t == self.any then isAttrs else attrs: isAttrs attrs && all verify (attrValues attrs);
81 name = "listOf<${t.name}>";
83 # listOf<any> can be optimised to just isList
84 if t == self.any then isList else v: isList v && all verify v;
89 assert all isTypeDef types;
91 # Store a list of functions so we don't have to pay the cost of attrset lookups at runtime.
92 funcs = map (t: t.verify) types;
95 name = "union<${concatStringsSep "," (map (t: t.name) types)}>";
96 verify = v: any (func: func v) funcs;