Skip to content

Commit

Permalink
Merge pull request hylang#494 from theanalyst/fix/distinct
Browse files Browse the repository at this point in the history
faster distinct: maintain seen items in a set
  • Loading branch information
berkerpeksag committed Feb 4, 2014
2 parents e8dfe5b + a41a3c7 commit e6a6249
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions hy/core/language.hy
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit e6a6249

Please sign in to comment.