A formatter is a function [resolve] => translator, which create a translator, potentially based on other translators for a realm returned by the resolve function.
This namespace contains a collection of some standard formatters and utilities to build others.
A formatter is a function [resolve] => translator, which create a translator, potentially based on other translators for a realm returned by the resolve function. This namespace contains a collection of some standard formatters and utilities to build others.
(constants intern-extern-map)(constants intern-extern-map external-realm)Formatter that translates fixed values, like in a realm/enum
Usage:
(constants {:foo "foo"})
Formatter that translates fixed values, like in a realm/enum
Usage:
```
(constants {:foo "foo"})
```
(identity realm)Returns an identity formatter for the given realm. The formatter throws if the external value is not contained in the realm.
Returns an identity formatter for the given realm. The formatter throws if the external value is not contained in the realm.
(record-map record spec & {strict? :strict? defaults :defaults})Formatter to represent a record as a map with explicit keys.
Options are:
:strict?: if set then a format-error is thrown when the map contains
unknown keys. By default they are ignored.
:defaults: a map of defaults for record fields. If none is given then a
format-error is thrown if the parsed map does not contain a defined key.
Usage:
(record-map MyRecord
{my-rec-foo :foo
my-rec-bar :bar}
:defaults {my-rec-foo "value"})
or
(record-map MyRecord [:foo :bar])
Formatter to represent a record as a map with explicit keys.
Options are:
`:strict?`: if set then a format-error is thrown when the map contains
unknown keys. By default they are ignored.
`:defaults`: a map of defaults for record fields. If none is given then a
format-error is thrown if the parsed map does not contain a defined key.
Usage:
```
(record-map MyRecord
{my-rec-foo :foo
my-rec-bar :bar}
:defaults {my-rec-foo "value"})
```
or
```
(record-map MyRecord [:foo :bar])
```
(simple translator)A simple (non recursive) formatter.
A simple (non recursive) formatter.
(tagged-union-map tag-key content-key tag-realm-map)Formatter that distinguishes between different realms depending on a tag value in a map.
For example:
(tagged-union-map :tag :value {"foo" foo-realm})
returns a formatter that can be used for a union realm that contains foo-realm, where the formatted values look like:
{:tag "foo" :value <foo-value>}
Formatter that distinguishes between different realms depending on a
tag value in a map.
For example:
```
(tagged-union-map :tag :value {"foo" foo-realm})
```
returns a formatter that can be used for a union realm that contains `foo-realm`, where the formatted values look like:
```
{:tag "foo" :value <foo-value>}
```
(tagged-union-tuple tag-realm-map)Formatter that distinguishes between different realms depending on the value of the first part of a tuple.
For example:
(tagged-union-tuple {"foo" foo-realm})
returns a formatter that can be used for a union realm that contains foo-realm, where the formatted values look like:
["foo" <foo-value>]
Formatter that distinguishes between different realms depending on the
value of the first part of a tuple.
For example:
```
(tagged-union-tuple {"foo" foo-realm})
```
returns a formatter that can be used for a union realm that contains `foo-realm`, where the formatted values look like:
```
["foo" <foo-value>]
```
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 |