Skip to content

Instantly share code, notes, and snippets.

@jli
Created October 2, 2011 04:45
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 jli/1257064 to your computer and use it in GitHub Desktop.
Save jli/1257064 to your computer and use it in GitHub Desktop.
;; user> (partition* [1 2 3 4 5 6 7 8] 3)
;; ((1 2 3) (2 3 4) (3 4 5) (4 5 6) (5 6 7) (6 7 8))
(defn partition* [xs n]
(let [subs (loop [ys xs acc []]
(if (empty? ys)
acc
(recur (rest ys) (conj acc ys))))]
(take-while #(= (count %) n)
(map (partial take n) subs))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment