Skip to content

Instantly share code, notes, and snippets.

@dgellow
Created April 4, 2015 19:32
Show Gist options
  • Save dgellow/287edd1a03b5f736d91c to your computer and use it in GitHub Desktop.
Save dgellow/287edd1a03b5f736d91c to your computer and use it in GitHub Desktop.
clojure's thread-last macro, aka ->>, in wisp | See https://clojuredocs.org/clojure.core/-%3E%3E
(defmacro -->
[x & forms]
(let [next (fn [x] (let [r (rest x)] (if (empty? r) nil r)))]
(loop [x x, forms forms]
(if forms
(let [form (first forms)
threaded (if (list? form)
(with-meta
`(~(first form) ~@(next form) ~x)
(meta form))
(list form x))]
(recur threaded (next forms)))
x))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment