Liking cljdoc? Tell your friends :D

extend-clj.core


deftype-atomclj/smacro

(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.
sourceraw docstring

IAtom3clj/sprotocol

compare-and-set-implclj/s

(compare-and-set-impl this oldv newv)

deref-implclj/s

(deref-impl this)

notify-watchesclj/s

(notify-watches this oldv newv)

swap*clj/s

(swap* this f args)

validateclj/s

(validate this validator value)
source

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close