May 2018
Beginner to intermediate
290 pages
6h 43m
English
Returning to our book-inventory example, let’s imagine that we have a new requirement: we need to notify the corporate inventory system of each change in the inventory. Happily, someone else has written a function called notify-inventory-change that takes care of all the notification details. We just need to call it at the right times.
So rolling back to our original, atom-based code, our first stab at this is to just add a call to notify-inventory-change in the inventory-update function:
| | (def by-title (atom {})) |
| | |
| | (defn add-book [{title :title :as book}] |
| | (swap! |
| | by-title |
| | (fn [by-title-map] |
| | (notify-inventory-change :add book) |
| | (assoc by-title-map title book)))) |
| | |
| | ;; Similar logic in del-book. |
Life is good … until we ...
Read now
Unlock full access