Skip to content

Instantly share code, notes, and snippets.

@timmc
Created July 31, 2012 17:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timmc/3218623 to your computer and use it in GitHub Desktop.
Save timmc/3218623 to your computer and use it in GitHub Desktop.
variant on swap! that returns the old value
(defn swap2! [a f & args]
(let [oldp (promise)
f* (fn [oldv] (deliver oldp oldv) (apply f oldv args))]
(swap! a f*) @oldp))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment