Skip to content

Instantly share code, notes, and snippets.

@jmgimeno
Created February 24, 2012 16:04
Show Gist options
  • Save jmgimeno/1901772 to your computer and use it in GitHub Desktop.
Save jmgimeno/1901772 to your computer and use it in GitHub Desktop.
split-at-subsequence
(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