function | since v0.0-927 | clojure.core/distinct? | Edit |
(distinct? x)
(distinct? x y)
(distinct? x y & more)
Returns true if no two of the arguments are =
(distinct? 1)
;;=> true
(distinct? 1 2)
;;=> true
(distinct? 1 1)
;;=> false
(distinct? 1 2 3)
;;=> true
(distinct? 1 2 1)
;;=> false
Apply it a collection:
(apply distinct? [1 2 3])
;;=> true
(apply distinct? [1 2 1])
;;=> false
Returns true if no two of the arguments are =
(defn ^boolean distinct?
([x] true)
([x y] (not (= x y)))
([x y & more]
(if (not (= x y))
(loop [s #{x y} xs more]
(let [x (first xs)
etc (next xs)]
(if xs
(if (contains? s x)
false
(recur (conj s x) etc))
true)))
false)))