Skip to content

clojure.core/distinct

View this page on ClojureDocs

Type: function Added: Clojure 1.0 Examples: 4 Runnable: 3
([] [coll])

Returns a lazy sequence of the elements of coll with duplicates removed. Returns a stateful transducer when no collection is provided.

Examples

by zmila on
by zmila on . May have evaluation errors.
by siddharthjain-in on
by clojer on

Note by morphling

If you do not need the lazyness of distinct, set can be faster. Like: (count (set some-coll)).

Note by vshatsky

Use this function if you want to remove only consequtive duplicates

(defn distinct-consequtive [sequence] (map first (partition-by identity sequence)))

(distinct-consequtive [1 1 2 3 3 2 2 3])
;=> (1 2 3 2 3)

Note by bfontaine

Use dedupe if you want to remove consecutive duplicates, available since Clojure 1.7.

See also


Content from the matching ClojureDocs page, with authors credited on each contribution.