clojure

shaunlebron 2025-09-26T17:48:08.705419Z

A nice function for tapping values in nested expressions or threading macros:

(defn tap-> [x]
  (doto x tap>))

โž• 2
Alex Miller (Clojure team) 2025-09-26T17:51:18.710329Z

I think we have a jira for that :)

shaunlebron 2025-09-26T17:52:53.398519Z

"not worth doing"? https://clojure.atlassian.net/browse/CLJ-2538

shaunlebron 2025-09-26T17:53:41.943479Z

looks like the doto trick doesnโ€™t work inside ->>

โž• 1
shaunlebron 2025-09-26T17:59:26.282759Z

(-> :foo (doto tap>))
  (->> :foo (#(doto % tap>)))

2025-09-26T18:01:33.285689Z

Your function should work though right?

๐Ÿ‘ 1
2025-09-26T18:03:26.005329Z

I kind of always wished tap, print, println and company all returned their input to be honest. Returning nil is so un-useful

Alex Miller (Clojure team) 2025-09-26T18:08:08.537619Z

I donโ€™t think youโ€™d be too happy with print returning the value

โž• 1
๐Ÿค” 1
borkdude 2025-09-26T18:09:54.455319Z

(also, most print fns are variadiac, so should it then return the seq of args... doesn't make sense either)

shaunlebron 2025-09-26T18:10:46.122379Z

I agree with the sentiment but not good to change return value yeah

shaunlebron 2025-09-26T18:11:15.491489Z

being able to "tap" a value in a expression without disrupting it is whatโ€™s desired

2025-09-26T18:11:22.532999Z

Why not? I mean ignoring that it would be a breaking change

seancorfield 2025-09-26T18:12:51.435499Z

Any chance of CLJ-2538 being reopened/reconsidered?

๐Ÿ‘ 2
2025-09-26T18:13:29.339629Z

@borkdude I'd say yes. Then you could quickly print inputs to a fn call by just adding apply

seancorfield 2025-09-26T18:13:48.979439Z

ISTR at some point tap-> being mentioned as a possible candidate for 1.13:slightly_frowning_face:

shaunlebron 2025-09-26T18:14:40.464519Z

you mean tap-> right?

seancorfield 2025-09-26T18:14:55.980539Z

Er, yes. On my phone.

seancorfield 2025-09-26T18:15:13.949279Z

Fixed:grin:

Alex Miller (Clojure team) 2025-09-26T18:17:30.028759Z

Rich looked at it and said it wasnโ€™t worth it so whatโ€™s changed to reconsider?

shaunlebron 2025-09-26T18:21:03.967789Z

awkwardness of tapping values in ->>

(->> items
     (filter (str/includes? "foo" (:name %)))
     (#(doto % tap>)) ;; or `tap->`
     (map (juxt :id :name)))

โž• 2
2025-09-26T18:29:16.910579Z

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.

Alex Miller (Clojure team) 2025-09-26T18:47:08.751399Z

done

๐Ÿ™ 5
๐Ÿ™๐Ÿป 1
2025-09-26T18:47:49.914219Z

send our thanks to rich

seancorfield 2025-09-26T19:17:53.786269Z

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!

seancorfield 2025-09-26T19:23:25.843519Z

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 ๐Ÿ™‚

shaunlebron 2025-09-26T19:41:43.657289Z

@alexmiller I made a typo in my example that you pasted in Jira, the tap-> inside the doto should be tap>

๐Ÿ‘ 1