Created
October 2, 2011 04:45
-
-
Save jli/1257064 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; 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