Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HakimCassimallyBBC/10fdaec1d1907e758e92403933ada0c8 to your computer and use it in GitHub Desktop.
Save HakimCassimallyBBC/10fdaec1d1907e758e92403933ada0c8 to your computer and use it in GitHub Desktop.
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
Copy link
Author

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