Created
August 13, 2014 15:25
-
-
Save ilazarte/b2722a9e5eb285f559cb to your computer and use it in GitHub Desktop.
This file contains hidden or 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-every | |
"adapted from clojure core version of partition-by | |
partition a collection every time a predicate returns true | |
=> (partition-every keyword? [:a 1 2 3 :b :c 4 5 6 7 :d :e]) | |
((:a 1 2 3) (:b) (:c 4 5 6 7) (:d) (:e))" | |
[pred coll] | |
(lazy-seq | |
(when-let [s (seq coll)] | |
(let [fst (first s) | |
run (cons fst (take-while (complement pred) (next s)))] | |
(cons run (partition-every pred (seq (drop (count run) s)))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment