Last active
June 18, 2016 17:02
-
-
Save micha/2355d19343c693c853fe20f2f762307b 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
(defn partition-with | |
[partfn coll] | |
(->> coll (reduce (fn [xs x] | |
(let [c (peek xs) | |
p (conj c x)] | |
(if (partfn p) | |
(conj xs [x]) | |
(conj (pop xs) p)))) | |
[[]]))) | |
(partition-with | |
#(< 3 (apply + %)) | |
[1 1 1 1 1 1 1 1 1 1]) | |
;=> [[1 1 1] [1 1 1] [1 1 1] [1]] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment