Another tool that Clojure provides for working with agents is watchers. These are just functions that get a chance to peek at the agent's data. This happens after the validators have successfully run and the new data is set as the agent's state. Because of the way it's handled, the state may have changed again since then, but watchers give you the chance to look at and track the data separately.
This can help us keep an eye on the data as it's being processed. We can use it to log progress, sample the data for manual validation, or for a number of other tasks.
We'll use the dependencies and requirements that we did in the Managing program complexity with STM recipe. We'll also add a new import.
(import '[java.lang Thread])
And we'll use the data file from the Managing program complexity with STM recipe, and the lazy-read-csv
and with-header
functions from that recipe.
From the Maintaining data consistency with validators recipe, we'll use the int...