Living with Change
We’ve examined in detail several tools that Clojure provides for making updates to our application’s state. These tools guard against misadventure by ensuring that changes are valid and appear instantaneous. We can, however, still shoot ourselves in the foot with sloppy thinking.
It’s difficult to demonstrate the complexities of state management in the kind of toy code that festoons documentation, blog posts, and yes, even books like this one. It helps to keep a few guidelines in mind when applying the mechanisms we’ve seen in action.
How and When to Validate
Our shopping.store API contains a piece of redundancy and a little bit of nastiness. In init, we applied the no-negative-values? function to our inventory as a validator ...