Utilities for tapping Clojure forms.
- A Clojure/ClojureScript macro, named
let>
that works likelet
, and also willtap>
the let box (that's what I call that bininding vector). - A reader tag,
#t
that will tap the tagged form.
Dependency
;; deps.edn
{pez/taplet {:mvn/version "1.0.62"}}
;; Leiningen
[pez/taplet "1.0.62"]
Use let>
wherever you have a let
that you want to tap. Optionally label the taps using {:let> :some-label}
as metadata for the binding vector.
(comment
(require '[pez.taplet :refer [let>]])
(add-tap (partial println "tap>")) ;; Only for observability here
(let> [x 1
y 2
coords {:x x :y y}]
coords) ;; => {:x 1, :y 2}
;; tap> [x 1 y 2 coords {:x 1, :y 2}]
(let> ^{:let> :labeled-taps} [x 1
y 2
coords {:x x :y y}]
coords) ;; => {:x 1, :y 2}
;; tap> [:labeled-taps x 1 y 2 coords {:x 1, :y 2}]
(let> [x 1
{:keys [z] :as y} {:z 2}
[a [b {:keys [c d]}]] [:foo [:bar {:c :baz :d :gaz}]]]
[x z y a b c d]) ;; => [1 2 {:z 2} :foo :bar :baz :gaz]
;; tap> [x 1 y {:z 2} z 2 a :foo b :bar c :baz d :gaz]
:rcf)
To tap any value, prepend it with #t
. You'll need to “install” the reader tag once per
REPL session. If you plan to leave #t
in the code (or plan to sometimes forget to
remove it), you could consider adding it to a file that is always loaded early in app
the app start. (E.g. The topmost level namespace.)
(comment
(require '[pez.hasht]) ;; Only needed to be done once per REPL session
(add-tap (partial println "tap>")) ;; Only for observability here
#t (let [x 1
y 2
coords {:x x :y y}]
(:x #t coords)) ;; => 1
;; tap> {:x 1, :y 2}
;; tap> 1
:rcf)
MIT License, see LICENSE file