Returns a lazy sequence of the elements of coll with duplicates removed. Returns a stateful transducer when no collection is provided.
user=> (distinct [1 2 1 3 1 4 1 5]) (1 2 3 4 5)
user=> (def fractions (for [n (range 1 100) d (range (inc n) 100)] (let [gcd (clojure.contrib.math/gcd n d)] (/ (/ n gcd) (/ d gcd))))) ;; all irreducible fractions with denominator < 100 ;; (1/2 1/3 ... 1/99 2/3 1/2 2/5 1/3 ...) user=> (count fractions) 4851 user=> (count (distinct fractions)) 3003
user=> (distinct [1/2 2/4]) (1/2) user=> (distinct [1/2 0.5]) (1/2 0.5)
user=> (apply str (distinct "tattoo")) "tao"
Returns true if no two of the arguments are =
Returns a lazy sequence removing consecutive duplicates in coll. Returns a transducer when no coll...
Returns a set of the distinct elements of coll.
If you do not need the lazyness of distinct, set can be faster. Like: (count (set some-coll)).
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)
Use dedupe if you want to remove consecutive duplicates, available since Clojure 1.7.
dedupe