Search code examples
clojure

How to get older versions for clojure data structures


Clojure is using persistent data structures , is there a way to access older versions of vector or maps since it is keeping it internally ?

Lets say for a Vector ,what i meant is since clojure is not copying full structure and keeping it in a tree internally (see https://hypirion.com/musings/understanding-persistent-vector-pt-1) and keeps older structure values too, is there a way to use this to do some senarios like undo/redo or replay, It is using the same principle for Datomic to retrieve older version for data, so im asking if it is possible to get this in clojure.


Solution

  • As per Kris's comment, using add-watch is the right answer it seems , David Nolen has described this approach here https://swannodette.github.io/2013/12/31/time-travel