[英]How can I use Clojure's distinct? function on a collection?
Clojure 与众不同? 方法不采用集合,而是采用args列表
(distinct? x)
(distinct? x y)
(distinct? x y & more)
因此(distinct?0 0 0 0)正确返回false ,而(distinct?[0 0 0 0])返回true。 我该如何使用不同的? 在一个集合上,以便传递一个集合[0 0 0 0]将返回false,因为该集合包含重复项?
我确实意识到该函数正在正常运行,但我正在寻找一种技巧来将它应用于集合的内容而不是args列表。
作为一种解决方法,我目前有
(defn coll-distinct? [coll]
(= (distinct coll) coll))
但我觉得我错过了一种更优雅的方式重复使用?
如果要将参数作为seq传递给函数,请使用apply
。
(apply distinct? [1 2 3 1])
; false
(apply distinct? [1 2 3])
; true
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.