Skip to content

Instantly share code, notes, and snippets.

@michalmarczyk
Created July 6, 2013 02:40
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 michalmarczyk/5938407 to your computer and use it in GitHub Desktop.
Save michalmarczyk/5938407 to your computer and use it in GitHub Desktop.
;; [1 2 3] -> [1 [2 [3]]]
(defn f [xs]
(if (next xs)
[(first xs) (vec (f (next xs)))]
(vec xs)))
(defn g [v]
(reduce (fn [acc x]
[x acc])
[(peek v)]
(rseq (pop v))))
;; prefer g, of course
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment