diff options
author | Rich Hickey <richhickey@gmail.com> | 2008-03-17 13:44:08 +0000 |
---|---|---|
committer | Rich Hickey <richhickey@gmail.com> | 2008-03-17 13:44:08 +0000 |
commit | e8f4200da5b6243402fc95ca0cb7a183b60ce023 (patch) | |
tree | 1a153976e073a109700e3fac4ad16f897b623d3f /src | |
parent | 8f5eafce69ab8245a1cffaa38da8fcc332c1600b (diff) |
made distinct lazy
Diffstat (limited to 'src')
-rw-r--r-- | src/boot.clj | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/boot.clj b/src/boot.clj index ae23b3e4..c3be2d8f 100644 --- a/src/boot.clj +++ b/src/boot.clj @@ -1684,10 +1684,6 @@ make-proxy [classes method-map] "Returns a set of the distinct elements of coll." [coll] (apply hash-set coll)) -(defn distinct - "Returns a sequence of the elements of coll with duplicates removed" - [coll] (seq (set coll))) - (defn #^{:private true} filter-key [keyfn pred amap] (loop [ret {} es (seq amap)] @@ -2241,3 +2237,12 @@ make-proxy [classes method-map] ([k x y] (if (< (k x) (k y)) x y)) ([k x y & more] (reduce #(min-key k %1 %2) (min-key k x y) more))) + +(defn distinct + "Returns a lazy sequence of the elements of coll with duplicates removed" + [coll] + (let [step (fn step [[f & r :as xs] seen] + (when xs + (if (seen f) (recur r seen) + (lazy-cons f (step r (conj seen f))))))] + (step (seq coll) #{}))) |