Decoding and constructing Souther-generated domain values from Clojure data.
Souther generates, for every data type, a public decoder() (a Raoh Decoder) that runs the
type's invariants. Because data constructors are non-public, this decoder is the construction
path for a boundary that does not extends the generated code -- a Clojure proxy, or any
non-JVM-subclass consumer. This namespace wraps that path in Clojure terms: keyword-keyed maps
are accepted (keys are stringified to the field names the decoder expects), and a decode failure
comes back as Clojure data (Raoh Issues) rather than a Java Result to pick apart.
Decoding and constructing Souther-generated domain values from Clojure data. Souther generates, for every data type, a public `decoder()` (a Raoh `Decoder`) that runs the type's invariants. Because data constructors are non-public, this decoder is the construction path for a boundary that does not `extends` the generated code -- a Clojure `proxy`, or any non-JVM-subclass consumer. This namespace wraps that path in Clojure terms: keyword-keyed maps are accepted (keys are stringified to the field names the decoder expects), and a decode failure comes back as Clojure data (Raoh Issues) rather than a Java Result to pick apart.
(construct klass raw)Build an instance of the generated data type klass from Clojure raw, through the type's
public decoder() (which enforces its invariants). Throws ex-info if raw violates them.
For a newtype pass the bare value ((construct Balance 700)); for a unit case pass {}; for a
record pass a keyword-keyed map.
Build an instance of the generated data type `klass` from Clojure `raw`, through the type's
public `decoder()` (which enforces its invariants). Throws `ex-info` if `raw` violates them.
For a newtype pass the bare value (`(construct Balance 700)`); for a unit case pass `{}`; for a
record pass a keyword-keyed map.(decode decoder raw)Decode raw (Clojure data; keyword keys allowed) with a generated decoder. Returns
[:ok value] on success or [:err issues] on failure, where issues is a vector of
{:path :code :message} maps.
Decode `raw` (Clojure data; keyword keys allowed) with a generated `decoder`. Returns
`[:ok value]` on success or `[:err issues]` on failure, where issues is a vector of
`{:path :code :message}` maps.(decode! decoder raw)Like decode, but returns the value or throws ex-info carrying the issues under :issues.
Use at a trusted seam (e.g. building a result whose invariants cannot fail); prefer decode at
an untrusted boundary so the caller can report the issues.
Like `decode`, but returns the value or throws `ex-info` carrying the issues under `:issues`. Use at a trusted seam (e.g. building a result whose invariants cannot fail); prefer `decode` at an untrusted boundary so the caller can report the issues.
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 |