Clojure: distinct versus dedupe

by
, posted

clojure.core has two similar functions for lazily removing duplicates from a sequence: distinct and dedupe. What’s the difference?

distinct removes all duplicates from a sequence. For example:

(distinct [1 2 3 3 2 1])
;; (1 2 3)

dedupe only removes consecutive duplicates from a sequence. For example:

(dedupe [1 2 3 3 2 1])
;; (1 2 3 2 1)

Hope this helps!