(deftype-atom name fields & methods)Allows you to declare new type that will behave like native Clojure Atom,
but with custom deref and compare-and-set behaviors. Rest of swap!/reset!/
swap-vals!/reset-vals! will be implemented through these two.
Supports meta/validator/watches and ILookup for fields.
Syntax:
(deftype-atom <name> [<field> ...]
(deref-impl [this]
<impl>)
(compare-and-set-impl [this oldv newv]
<impl>))
To use this structure, use (-><name> <field> ...) function. E.g. if you
(deftype-atom X [a b c])
then create instances like
(->X a b c)
You can add more interfaces after deref-impl/compare-and-set-impl and implement them as you wish:
(deftype-atom <name> [<field> ...]
(deref-impl [this]
<impl>)
(compare-and-set-impl [this oldv newv]
<impl>)
clojure.lang.Counted
(count [this]
7)
clojure.lang.IBlockingDeref
(deref [this ms timeout]
(.deref this)))
Warning: swap-vals! and reset-vals! don’t work in ClojureScript.
Allows you to declare new type that will behave like native Clojure Atom,
but with custom `deref` and `compare-and-set` behaviors. Rest of swap!/reset!/
swap-vals!/reset-vals! will be implemented through these two.
Supports meta/validator/watches and ILookup for fields.
Syntax:
(deftype-atom <name> [<field> ...]
(deref-impl [this]
<impl>)
(compare-and-set-impl [this oldv newv]
<impl>))
To use this structure, use `(-><name> <field> ...)` function. E.g. if you
(deftype-atom X [a b c])
then create instances like
(->X a b c)
You can add more interfaces after deref-impl/compare-and-set-impl and implement them as you wish:
(deftype-atom <name> [<field> ...]
(deref-impl [this]
<impl>)
(compare-and-set-impl [this oldv newv]
<impl>)
clojure.lang.Counted
(count [this]
7)
clojure.lang.IBlockingDeref
(deref [this ms timeout]
(.deref this)))
Warning: swap-vals! and reset-vals! don’t work in ClojureScript.(compare-and-set-impl this oldv newv)(deref-impl this)(notify-watches this oldv newv)(swap* this f args)(validate this validator 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 |