I have this nagging problem:
Wrappers are functions that take a function, and returns another function that takes in a parameter, does something to the parameter and sticks it back into the function.
(defn wrapper [func] (fn [params] (func (do-something-to params))))
and what I'd like to do is to track parameter changes as it goes from wrapper to wrapper
for example, I can define two wrappers:
(defn wrap-inc [func] (comp func inc)) (defn wrap-double [func] (comp func #(* % 2)))
then,
(def h (-> #(* % 3) wrap-inc wrap-double))
is equivalent to:
(def h (fn [x] (* (inc (* 2 x)) 3))) (h 1) => 9
Now, I would want to define dbg->
so that
(def h-dbg (dbg-> #(* % 3) wrap-inc wrap-double))
to still give me the same functional equivalent, but also keep track of old and new values:
(h-dbg 1) => 9
but will also display debug infomation in the console:
"wrap-double: (in: 1, out: 2)" "wrap-inc: (in: 2, out 3)"
This sort of pattern will be extremely useful to debug ring wrappers like this to figure out what each one is doing, for example, this typical example:
(defn start [] (jetty/run-jetty (-> #'routes-handler ;;(wrap-reload-modified ["clj-src"]) (wrap-file "resources/public") wrap-file-info wrap-decamelcase-params wrap-keyword-params wrap-nested-params wrap-params wrap-ignore-trailing-slash) {:port 8890 :join? false}))