Created
November 18, 2009 12:24
-
-
Save lambder/237783 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 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