store/[org.clojure/clojure "1.8.0"] clj::clojure.core/set-validator!

Official Documentation

Add notes
Arities
==================================================
   [iref validator-fn]

Docstring
==================================================
  Sets the validator-fn for a var/ref/agent/atom. validator-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
  validator-fn should return false or throw an exception. If the current state (root
  value if var) is not acceptable to the new validator, an exception
  will be thrown and the validator will not be changed.

Source

(defn set-validator!
  "Sets the validator-fn for a var/ref/agent/atom. validator-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
  validator-fn should return false or throw an exception. If the current state (root
  value if var) is not acceptable to the new validator, an exception
  will be thrown and the validator will not be changed."
  {:added "1.0"
   :static true}
  [^clojure.lang.IRef iref validator-fn] (. iref (setValidator validator-fn)))

Example 1

Edit
(def atm (atom [2]))
;; => #'user/atm

(set-validator! atm #(every? even? %))
;; => nil

(swap! atm into [5])
;; => #<CompilerException java.lang.IllegalStateException: Invalid reference state (NO_SOURCE_FILE:0)>

(set-validator! atm nil)
;; => nil

(swap! atm into [5])
;; => [2 5]

Uses on crossclj