As with many design patterns, you can implement this as a function in clojure. It depends a little on how you represent the state in your program (refs, atom, agents) through the process, very similar.
You simply add an observer function to the agent / ref / atom of your state , which adds state to the cancellation list with each update. then your undo function just looks in the undo list. This has the nice effect of adding your to your cancellation list, allowing you to also repeat
My first impression is that ref
may be the right tool for this, because you can restore them all in a coordinated way, unless, of course, you can reduce your programs to one identifier (in Clojure, the meaning of the word), then you will not need coordinated update and the agent will work.
source share