Skip to content

Instantly share code, notes, and snippets.

@tgk
Created June 17, 2013 12:48
Show Gist options
  • Save tgk/5796601 to your computer and use it in GitHub Desktop.
Save tgk/5796601 to your computer and use it in GitHub Desktop.
Generate splits over a sequence in Clojure on lazy sequences. Drops last split at the moment.
(defn splits
[s]
(take-while
(comp seq second)
(iterate
(fn [[prefix suffix]]
[(conj prefix (first suffix))
(rest suffix)])
[[] s])))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment