function | since v0.0-927 | clojure.core/atom | Edit |
(atom x)
(atom x & {:keys [meta validator]})
(atom x)
- creates atom with initial value of x
(atom x opts)
- adds metadata or validator to atom
opts
is an optional map with optional keys :meta
and :validator
.
:meta
should be a metadata-map for the atom.
:validator
should be a validator function for the atom. See set-validator!
for more information.
(def a (atom 1))
@a
;;=> 1
(reset! a 2)
@a
;;=> 2
(swap! a inc)
@a
;;=> 3
Creates and returns an Atom with an initial value of x and zero or more options (in any order): :meta metadata-map :validator validate-fn If metadata-map is supplied, it will become the metadata on the atom. validate-fn must be nil or a side-effect-free fn of one argument, which will be passed the intended new state on any state change. If the new state is unacceptable, the validate-fn should return false or throw an Error. If either of these error conditions occur, then the value of the atom will not change.
(defn atom
([x] (Atom. x nil nil nil))
([x & {:keys [meta validator]}] (Atom. x meta validator nil)))