function | since v0.0-927 | clojure.core/swap! | Edit |

`(swap! a f)`

`(swap! a f x)`

`(swap! a f x y)`

`(swap! 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 the value that was swapped in.

Source docstring:

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 the value that was swapped in.

Source code @ clojurescript:src/main/cljs/cljs/core.cljs

```
(defn swap!
([a f]
(if (instance? Atom a)
(reset! a (f (.-state a)))
(-swap! a f)))
([a f x]
(if (instance? Atom a)
(reset! a (f (.-state a) x))
(-swap! a f x)))
([a f x y]
(if (instance? Atom a)
(reset! a (f (.-state a) x y))
(-swap! a f x y)))
([a f x y & more]
(if (instance? Atom a)
(reset! a (apply f (.-state a) x y more))
(-swap! a f x y more))))
```