calip/wrap: wrap functions in any function (a.k.a. "around advice"), without changing the code=> (calip/wrap #{#'user/rsum}
(fn [fname f & args]
(println "calling" fname "with" args)
(apply f args)))
wrapping #'user/rsum in :wrap
=> (rsum 10)
calling #'user/rsum with (10)
45
an advice takes a function name (var), the function itself and its arguments: (fn [fname f & args] ...)
it decides whether to call the function, how many times, with which arguments and what to return: retry, short circuit, redact, etc.
calip/unwrap: removes calip wrappers from functions: all of them, or just one by {:id ...}measure and trace are now built on top of wrap (they are just two built in advices):measure, :trace, :wrap (default for calip/wrap) or any custom one via {:id ...}=> (calip/measure #{#'user/connect})
=> (calip/trace #{#'user/connect})
=> (calip/wrap #{#'user/connect} retry {:id :retry})
the last added wrapper is the outermost one. wrapping again with the same id replaces that wrapper.
measure and trace take an optional :id as well, i.e. to measure the same function with two different reportersuncalip no longer removes all the hooks from a function: hooks that are not added by calip (i.e. directly via robert.hooke) are left alonetrace after measure (or vice versa) no longer silently replaces the previous wrapper"#'user/*") only wrap functions: values, macros and multimethods are skipped(wrapped) only contains resolved vars (it used to contain a mix of vars and strings, depending on what was passed in)calip, on-error, uncalip and untrace docstrings are now real docstringsa few behavior changes to be aware of:
(calip/wrapped) returns a map of functions to their wrapper ids instead of a set of functions=> (calip/wrapped)
{#'user/connect #{:measure :trace :retry}
#'user/rsum #{:wrap}}
(calip/uncalip (calip/wrapped)) still works and removes all the wrappers
untrace only removes :trace wrappers (it used to remove all of them), use uncalip / unwrap to remove allwrapping #'user/rsum in :trace ;; was: wrapping #'user/rsum in µ/trace
remove :trace wrapper from #'user/rsum ;; was: remove a wrapper from #'user/rsum
skipping #'user/+version+ since it is not a function
it can still be silenced with calip/*silent*
Can you improve this documentation?Edit on GitHub
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |