Created
September 10, 2016 18:41
-
-
Save noisesmith/268087fbce11dbab541185b13dd4ee54 to your computer and use it in GitHub Desktop.
using add-watch to track past states of an atom
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Clojure 1.8.0 | |
| +user=> (def a (atom nil)) | |
| #'user/a | |
| +user=> (def s (atom [])) | |
| #'user/s | |
| +user=> (add-watch a :state-watcher (fn [_ _ _ n] (swap! s conj n))) | |
| #object[clojure.lang.Atom 0x928763c {:status :ready, :val nil}] | |
| +user=> (swap! a conj :initial) | |
| (:initial) | |
| +user=> @s | |
| [(:initial)] | |
| +user=> (swap! a conj :next-value) | |
| (:next-value :initial) | |
| +user=> @s | |
| [(:initial) (:next-value :initial)] | |
| +user=> (reset! a :whatever) | |
| :whatever | |
| +user=> @s | |
| [(:initial) (:next-value :initial) :whatever] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment