Skip to content

Instantly share code, notes, and snippets.

@tgk
Created May 11, 2010 07:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tgk/397022 to your computer and use it in GitHub Desktop.
Save tgk/397022 to your computer and use it in GitHub Desktop.
(defn converging-seq
"Generates a sequence with terminates when two successive elements
from coll are identical.
(converged-seq [1 2 3 4 4 5 6]) => [1 2 3 4]"
[coll]
(cons
(first coll)
(map second
(take-while (fn [[prev curr]] (not (= prev curr)))
(partition 2 1 coll)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment