distinct

functionsince v0.0-927 clojure.core/distinctEdit
(distinct)
(distinct coll)

Details:

Returns a lazy sequence of the elements of coll with duplicates removed.


See Also:


Source docstring:
Returns a lazy sequence of the elements of coll with duplicates removed.
Returns a stateful transducer when no collection is provided.
Source code @ clojurescript:src/main/cljs/cljs/core.cljs
(defn distinct
  ([]
    (fn [rf]
      (let [seen (volatile! #{})]
        (fn
          ([] (rf))
          ([result] (rf result))
          ([result input]
            (if (contains? @seen input)
              result
              (do (vswap! seen conj input)
                  (rf result input))))))))
  ([coll]
    (let [step (fn step [xs seen]
                 (lazy-seq
                   ((fn [[f :as xs] seen]
                      (when-let [s (seq xs)]
                        (if (contains? seen f)
                          (recur (rest s) seen)
                          (cons f (step (rest s) (conj seen f))))))
                     xs seen)))]
      (step coll #{}))))