Skip to content

Instantly share code, notes, and snippets.

@ninjudd
Created August 26, 2011 05:46
Show Gist options
  • Save ninjudd/1172787 to your computer and use it in GitHub Desktop.
Save ninjudd/1172787 to your computer and use it in GitHub Desktop.
(defn partition-with
"Applies f to each value in coll, splitting it each time f returns true.
Returns a lazy seq of partitions."
[f coll]
(lazy-seq
(when-let [s (seq coll)]
(let [[head tail] (split-with (complement f) (rest coll))]
(cons (cons (first coll) head)
(partition-with f tail))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment