A nice function for tapping values in nested expressions or threading macros:
(defn tap-> [x]
(doto x tap>))I think we have a jira for that :)
"not worth doing"? https://clojure.atlassian.net/browse/CLJ-2538
looks like the doto trick doesnโt work inside ->>
(-> :foo (doto tap>))
(->> :foo (#(doto % tap>)))Your function should work though right?
I kind of always wished tap, print, println and company all returned their input to be honest. Returning nil is so un-useful
I donโt think youโd be too happy with print returning the value
(also, most print fns are variadiac, so should it then return the seq of args... doesn't make sense either)
I agree with the sentiment but not good to change return value yeah
being able to "tap" a value in a expression without disrupting it is whatโs desired
Why not? I mean ignoring that it would be a breaking change
Any chance of CLJ-2538 being reopened/reconsidered?
@borkdude I'd say yes. Then you could quickly print inputs to a fn call by just adding apply
ISTR at some point tap-> being mentioned as a possible candidate for 1.13:slightly_frowning_face:
you mean tap-> right?
Er, yes. On my phone.
Fixed:grin:
Rich looked at it and said it wasnโt worth it so whatโs changed to reconsider?
awkwardness of tapping values in ->>
(->> items
(filter (str/includes? "foo" (:name %)))
(#(doto % tap>)) ;; or `tap->`
(map (juxt :id :name)))reconsider that it would benefit a lot of users. i've written a version of spy countless times but basically never reach for tap because the places where i want to track like that is in pipelines or when i'm debugging.
done
send our thanks to rich
Yeah, appreciated! I end up writing that (doto .. tap>) so many times in every single project -- I even have a Joyride script to automate it!
https://github.com/seancorfield/vscode-calva-setup/blob/develop/joyride/scripts/tap.cljs in case anyone is interested. If you use it inside a -> it adds (doto tap>) at the cursor, otherwise it wraps the current form in (doto .. tap>) -- I'd say 90% of my usage is inside -> and I'd much rather just type tap-> than ctrl+alt+d ctrl+alt+t and invoke a script ๐
@alexmiller I made a typo in my example that you pasted in Jira, the tap-> inside the doto should be tap>