Created
February 24, 2012 16:04
-
-
Save jmgimeno/1901772 to your computer and use it in GitHub Desktop.
split-at-subsequence
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 split-at-subsequence [mark input] | |
(when-let [sequence (seq input)] | |
(let [len (count mark) | |
mark-seq (seq mark) | |
partition (partition-all len 1 sequence) | |
step (fn step [pieces] | |
(when pieces | |
(let [[fst rst] (split-with #(not= mark-seq %) pieces) | |
tail (lazy-seq (step (nthnext rst len)))] | |
(if (empty? fst) | |
tail | |
(cons (map first fst) tail)))))] | |
(step partition)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment