Public API of closed-record: a record type that does not permit assoc of undeclared keys or dissoc of declared keys.
Public API of closed-record: a record type that does not permit assoc of undeclared keys or dissoc of declared keys.
(check x)Return x if x is a closed record with no extra literal keys.
Throw ex-info with :type :closed-record/extra-keys (and :record, :keys) if x is a closed record read from a literal with undeclared keys. Throw ex-info with :type :closed-record/not-closed-record (and :value-class) for any other value, including nil.
Return x if x is a closed record with no extra literal keys. Throw ex-info with :type :closed-record/extra-keys (and :record, :keys) if x is a closed record read from a literal with undeclared keys. Throw ex-info with :type :closed-record/not-closed-record (and :value-class) for any other value, including nil.
(defclosedrecord name [& fields] & opts+specs)(defclosedrecord Name [fields*] options* specs*)
Same syntax as defrecord. Defines a record type with closed keys:
Lookup of an undeclared key gives the not-found value. Extra keys of a
map literal #ns.Name{...} are hidden; use check to find them.
Name is the type name symbol. fields is a vector of field symbols; each field declares its corresponding keyword key. specs supplies protocol or interface names and method implementations, as in defrecord. Options are keyword/value pairs before specs. Supported options are :no-print and :load-ns, passed to the JVM type compiler as in defrecord.
Defines ->Name, which takes one value per field in declaration order, and map->Name, which takes a map of keyword keys to field values. Missing declared keys in map->Name have nil values.
Rejected operations throw ex-info. Its ex-data contains :type and :record (the record class). Rejected assoc and dissoc also include :key; map->Name includes :keys (the set of undeclared keys). dissoc of an undeclared key returns the same record.
Extra literal keys do not affect lookup, entries, equality, hash, or print. Compilation of a literal as a code constant and print/read round trips discard extra keys. Call check on a runtime-read literal before those operations; check cannot find keys that have already been discarded.
(defclosedrecord Name [fields*] options* specs*)
Same syntax as defrecord. Defines a record type with closed keys:
- assoc (also conj, merge, into, update) of an undeclared key throws
ex-info with :type :closed-record/undeclared-key.
- dissoc of a declared key throws :closed-record/declared-key-dissoc.
- empty throws :closed-record/empty.
- map->Name with an undeclared key throws :closed-record/extra-keys.
Lookup of an undeclared key gives the not-found value. Extra keys of a
map literal `#ns.Name{...}` are hidden; use check to find them.
Name is the type name symbol. fields is a vector of field symbols;
each field declares its corresponding keyword key. specs supplies protocol
or interface names and method implementations, as in defrecord.
Options are keyword/value pairs before specs. Supported options are
:no-print and :load-ns, passed to the JVM type compiler as in defrecord.
Defines ->Name, which takes one value per field in declaration order,
and map->Name, which takes a map of keyword keys to field values.
Missing declared keys in map->Name have nil values.
Rejected operations throw ex-info. Its ex-data contains :type and
:record (the record class). Rejected assoc and dissoc also include :key;
map->Name includes :keys (the set of undeclared keys).
dissoc of an undeclared key returns the same record.
Extra literal keys do not affect lookup, entries, equality, hash, or print.
Compilation of a literal as a code constant and print/read round trips
discard extra keys. Call check on a runtime-read literal before those
operations; check cannot find keys that have already been discarded.cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |