Clojure的distinct?方法不接受集合,而是一系列参数的列表。
(distinct? x)
(distinct? x y)
(distinct? x y & more)
所以(distinct? 0 0 0 0)正确地返回false,而(distinct? [0 0 0 0])返回true。我该如何在集合上使用distinct?,以便传递一个包含重复项的集合[0 0 0 0]会返回false?
我确实意识到函数的执行是正确的,但我正在寻找一种技巧,将其应用于集合的内容而不是参数列表。
作为解决方法,我目前有:
(defn coll-distinct? [coll]
(= (distinct coll) coll))
但我觉得我错过了一种更优雅的复用“distinct”的方式。