Skip to content

Instantly share code, notes, and snippets.

@micha
Last active June 18, 2016 17:02
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 micha/2355d19343c693c853fe20f2f762307b to your computer and use it in GitHub Desktop.
Save micha/2355d19343c693c853fe20f2f762307b to your computer and use it in GitHub Desktop.
(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