Jakub Holý on copying :pre and :post conditions

(written by lawrence krubner, however indented passages are often quotes). You can contact lawrence at: lawrence@krubner.com, or follow me on Twitter.

Obviously I have read this article before (I offered response and was quoted before) but I’ve gone back to read it again and this jumped out at me:

Do you repeat the same checks again and again? Then you could either copy them using with-meta (they end-up in metadata anyway) or reuse the explicitly:

(defn with-valid-car [f] (fn [car] {:pre [:make :model :year]} (f car)))
(def count-price (with-valid-car (fn [car] (do-something car))))
;; or make & use a macro to make it nicer

That is clever. I am not sure why I overlooked that the first time. I like the idea of a factory for copying the :pre and :post conditions this way.