Skip to content

Instantly share code, notes, and snippets.

@craftybones
Created September 1, 2019 12:53
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 craftybones/ebfcaabcab103681743c1994484d3a65 to your computer and use it in GitHub Desktop.
Save craftybones/ebfcaabcab103681743c1994484d3a65 to your computer and use it in GitHub Desktop.
(def code '(+ 2 (+ 3 4)))
(defn wrangle [code]
(loop [c code
newc '()]
(if (seq? (last c))
(recur (last c) (conj newc (butlast c)))
(conj newc (butlast c) (last c) '->>))))
; user=> (wrangle code)
; (->> 4 (+ 3) (+ 2))
; user=> (def code '(inc (inc (* 4 5 (/ 6 2)))))
; #'user/code
; user=> (wrangle code)
; (->> 2 (/ 6) (* 4 5) (inc) (inc))
; user=>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment