@@ -4423,27 +4423,57 @@ reduces them without incurring seq initialization"
44234423 new-value))
44244424 (-reset! a new-value)))
44254425
4426+ (defn reset-vals!
4427+ " Sets the value of atom to newval. Returns [old new], the value of the
4428+ atom before and after the reset."
4429+ {:added " 1.9" }
4430+ [a new-value]
4431+ (let [validate (.-validator a)]
4432+ (when-not (nil? validate)
4433+ (when-not (validate new-value)
4434+ (throw (js/Error. " Validator rejected reference state" ))))
4435+ (let [old-value (.-state a)]
4436+ (set! (.-state a) new-value)
4437+ (when-not (nil? (.-watches a))
4438+ (-notify-watches a old-value new-value))
4439+ [old-value new-value])))
4440+
44264441(defn swap!
44274442 " Atomically swaps the value of atom to be:
44284443 (apply f current-value-of-atom args). Note that f may be called
44294444 multiple times, and thus should be free of side effects. Returns
44304445 the value that was swapped in."
44314446 ([a f]
4432- (if (instance? Atom a)
4433- (reset! a (f (.-state a)))
4434- (-swap! a f)))
4447+ (if (instance? Atom a)
4448+ (reset! a (f (.-state a)))
4449+ (-swap! a f)))
4450+ ([a f x]
4451+ (if (instance? Atom a)
4452+ (reset! a (f (.-state a) x))
4453+ (-swap! a f x)))
4454+ ([a f x y]
4455+ (if (instance? Atom a)
4456+ (reset! a (f (.-state a) x y))
4457+ (-swap! a f x y)))
4458+ ([a f x y & more]
4459+ (if (instance? Atom a)
4460+ (reset! a (apply f (.-state a) x y more))
4461+ (-swap! a f x y more))))
4462+
4463+ (defn swap-vals!
4464+ " Atomically swaps the value of atom to be:
4465+ (apply f current-value-of-atom args). Note that f may be called
4466+ multiple times, and thus should be free of side effects.
4467+ Returns [old new], the value of the atom before and after the swap."
4468+ {:added " 1.9" }
4469+ ([a f]
4470+ (reset-vals! a (f (.-state a))))
44354471 ([a f x]
4436- (if (instance? Atom a)
4437- (reset! a (f (.-state a) x))
4438- (-swap! a f x)))
4472+ (reset-vals! a (f (.-state a) x)))
44394473 ([a f x y]
4440- (if (instance? Atom a)
4441- (reset! a (f (.-state a) x y))
4442- (-swap! a f x y)))
4474+ (reset-vals! a (f (.-state a) x y)))
44434475 ([a f x y & more]
4444- (if (instance? Atom a)
4445- (reset! a (apply f (.-state a) x y more))
4446- (-swap! a f x y more))))
4476+ (reset-vals! a (apply f (.-state a) x y more))))
44474477
44484478(defn compare-and-set!
44494479 " Atomically sets the value of atom to newval if and only if the
0 commit comments