(swap-vals! a f)
(swap-vals! a f x)
(swap-vals! a f x y)
(swap-vals! a f x y & more)
Atomically swaps the value of atom to be:
(apply f current-value-of-atom args). Note that f may be called
multiple times, and thus should be free of side effects.
Returns [old new], the value of the atom before and after the swap.
Source
(defn
swap-vals!
"Atomically swaps the value of atom to be:\n (apply f current-value-of-atom args). Note that f may be called\n multiple times, and thus should be free of side effects.\n Returns [old new], the value of the atom before and after the swap."
{:added "1.9"}
([a f] (reset-vals! a (f (.-state a))))
([a f x] (reset-vals! a (f (.-state a) x)))
([a f x y] (reset-vals! a (f (.-state a) x y)))
([a f x y & more] (reset-vals! a (apply f (.-state a) x y more))))