Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
(defn split-by
"Create from sequence (l) sequence of sequences with specified number of elemenets (c)
Example:
(split-by 2 [1 2 3 4 5 6 7])
=> '((1 2) (3 4) (5 6) (7))"
[c l]
(if (seq l)
(cons (take c l) (split-by c (drop c l)))))
(defn split-into-chunks
"Split sequence (l) into specified number of chunks (c)
Example:
(split-into-chunks 3 [1 2 3 4 5 6 7])
=> '((1 2 3) (4 5 6) (7))"
[c l]
(split-by (inc (int (/ (count l) c))) l))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment