(defprotocol protocol-sym & specs)Defines a native Clojure protocol whose methods carry Malli schemas.
This is the core malt API entrypoint.
Method specs take param/schema pairs followed by a return schema and an
optional (throws [...]) clause for checked exceptions:
(defprotocol UserStore
(create-user [name :string age :int] :string)
(suspend-user! [id :string]
:nil
(throws [not-found])))
All provided data is made available on the produced protocol var and can be
accessed through #':
(malt/defprotocol Foo
(foo [name :string]
:string))
#'UserStore
;; =>
{:malt/protocol true
:sigs {:create-user
{:malt/params [name]
:malt/param-schemas {:name :string}
:malt/arguments-schema [:cat :string]
:malt/return-schema :string
:malt/arguments-validator #object[...]
:malt/return-validator #object[...]}}}
Also defines a ?Name var containing a Malli schema which can be used to
assert a value implements the protocol. This is done through satisfies?.
Defines a native Clojure protocol whose methods carry Malli schemas.
This is the core malt API entrypoint.
Method specs take param/schema pairs followed by a return schema and an
optional `(throws [...])` clause for checked exceptions:
```clojure
(defprotocol UserStore
(create-user [name :string age :int] :string)
(suspend-user! [id :string]
:nil
(throws [not-found])))
```
All provided data is made available on the produced protocol var and can be
accessed through `#'`:
```clojure
(malt/defprotocol Foo
(foo [name :string]
:string))
#'UserStore
;; =>
{:malt/protocol true
:sigs {:create-user
{:malt/params [name]
:malt/param-schemas {:name :string}
:malt/arguments-schema [:cat :string]
:malt/return-schema :string
:malt/arguments-validator #object[...]
:malt/return-validator #object[...]}}}
```
Also defines a `?Name` var containing a Malli schema which can be used to
assert a value implements the protocol. This is done through `satisfies?`.(defrecord record-sym & specs)Defines a native Clojure record with schema-validated constructors.
Fields are given as field/schema pairs. Inline implementations of malt protocols are wrapped with input/output validation:
(defrecord UserStoreImpl
[db ?DataSource]
UserStore
(create-user [_ name age]
(persist-user db name age)))
Overrides the generated ->Name and map->Name constructors to validate
their inputs, and additionally defines ?NameSchema (a Malli :map schema of
the fields) and ?Name (an instance? check).
Defines a native Clojure record with schema-validated constructors.
Fields are given as field/schema pairs. Inline implementations of malt
protocols are wrapped with input/output validation:
```clojure
(defrecord UserStoreImpl
[db ?DataSource]
UserStore
(create-user [_ name age]
(persist-user db name age)))
```
Overrides the generated `->Name` and `map->Name` constructors to validate
their inputs, and additionally defines `?NameSchema` (a Malli :map schema of
the fields) and `?Name` (an `instance?` check).(extend-type type-sym & protocol+method-forms)Like [clojure.core/extend-type], but methods of malt protocols are wrapped with input/output validation.
Additionally supports passing a namespace-qualified record symbol (for
example other.ns/SomeRecord) which is resolved to the underlying class.
Like [clojure.core/extend-type], but methods of malt protocols are wrapped with input/output validation. Additionally supports passing a namespace-qualified record symbol (for example `other.ns/SomeRecord`) which is resolved to the underlying class.
(reify & protocol+method-forms)Like [clojure.core/reify], but methods of malt protocols are wrapped with input/output validation.
Like [clojure.core/reify], but methods of malt protocols are wrapped with input/output validation.
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 |