Skip to content

Instantly share code, notes, and snippets.

@tgk
Forked from kasperlanger/converging.clj
Created May 19, 2010 05:02
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/405972 to your computer and use it in GitHub Desktop.
Save tgk/405972 to your computer and use it in GitHub Desktop.
(defn converging-seq
[coll]
(for [[x y] (partition 2 1 (cons ::not-an-element coll)) :while (not (= x y))] y))
(defn converging-seq2
[[x y & tl]]
(cond (nil? x) []
(nil? y) [x]
(= x y) [x]
:else (lazy-seq (cons x (converging-seq2 (cons y tl))))))
@tgk
Copy link
Author

tgk commented May 19, 2010

Fixed problem with sequences starting with nil. (converging-seq [nil 1 2 2]) => [] before.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment