Skip to content

Instantly share code, notes, and snippets.

@zaphar
Created February 19, 2010 06:01
Show Gist options
  • Select an option

  • Save zaphar/308479 to your computer and use it in GitHub Desktop.

Select an option

Save zaphar/308479 to your computer and use it in GitHub Desktop.
(defn distinctp
"Returns a lazy sequence of the elements of coll with duplicates removed"
[pred coll]
(let [step (fn step [xs seen]
(lazy-seq
((fn [[f :as xs] seen]
(when-let [s (seq xs)]
(if (contains? seen (pred f))
(recur (rest s) seen)
(cons f (step (rest s) (conj seen (pred f)))))))
xs seen)))]
(step coll #{})))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment