Merge pull request #494 from theanalyst/fix/distinct

faster distinct: maintain seen items in a set
This commit is contained in:
Berker Peksag 2014-02-03 21:22:03 -08:00
commit e6a6249eab

View File

@ -75,12 +75,12 @@
(defn distinct [coll]
"Return a generator from the original collection with duplicates
removed"
(let [[seen []] [citer (iter coll)]]
(let [[seen (set)] [citer (iter coll)]]
(for* [val citer]
(if (not_in val seen)
(do
(yield val)
(.append seen val))))))
(.add seen val))))))
(defn drop [count coll]
"Drop `count` elements from `coll` and yield back the rest"