Reputation: 58826
I have a vector which contains a list of Hash maps in Clojure and I have an add-watch on this vector to see any changes made. Is there an easy way to do a diff on the changes made to the hash map, so that maybe I could get a list of just the changed entries in the hash?
Note: This follows on from some earlier posts I have had where I have tried to persist changes to a database for a data structure stored in a ref. I have realised that the easiest way to save state is simple to watch the ref for changes and then store those changes. My ideal solution would be if the add-watch was passed a changelist as well :)
Upvotes: 2
Views: 1264
Reputation: 106401
You probably need to define "diff" a little more precisely. For example, does an insertion in the middle of the vector count as a single change or as a change of that element and all subsequent ones? Also are your vectors guaranteed to be the same length?
Having said that, the simple approach would be something like:
Upvotes: 1