Create a gist now

Instantly share code, notes, and snippets.

and-> function to add a parenthesis to a threading form
boot.user=> (defn and->> [f value] (doto value f))
#'boot.user/and->>
boot.user=> (defn and-> [value f] (doto value f))
#'boot.user/and->
;; use the appropriate and->(>) form for your threading macro
boot.user=> (-> 1 (and-> println))
1
1
;; or ignore the value passed in
boot.user=> (->> 1 (and->> (fn [_] (println "hello"))))
hello
1
boot.user=> (-> 1 (and-> (fn [_] (println "hello"))))
hello
1
;; or perhaps using `constantly`?
(-> 1 (and-> (constantly (println "hello")))
@HakimCassimallyBBC

Suggested enhancement:

<dysfun>	 (defmacro &-> [value & fs] `(let [v# ~value] (doto v# (some-> v# ~@fs))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment