Skip to content

Instantly share code, notes, and snippets.

@lambder
Created November 18, 2009 12:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save lambder/237783 to your computer and use it in GitHub Desktop.
Save lambder/237783 to your computer and use it in GitHub Desktop.
(defn multi-split-with
"Returns a lazy collection of lists which elements ..."
[pred coll]
(let [[head tail] (split-with pred coll)
tail-without-seps (drop-while (complement pred) tail)]
(lazy-seq
(if (seq tail-without-seps)
(cons head (multi-split-with pred tail-without-seps))
(list head)))))
(defn multi-split-with-not-so-lazy
"Returns a lazy collection of lists which elements ..."
[pred coll]
(let [[head tail] (split-with pred coll)]
(if (seq tail)
(lazy-seq
(cons head
(remove empty? (multi-split-with-not-so-lazy pred
(drop-while (complement pred) tail)))))
(list head))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment