如何检查 spec/coll-of 中的不同 ID

How to check distinct id in spec/coll-of

(s/def ::users (s/coll-of ::user :distinct true))

上面的规范要求每个用户映射都是不同的,但我如何指定它来检查不同的 :user/ids

不应允许以下集合:

[{:id 10 :name "Jessica"} {:id 10 :name "Erica"}]
(s/def ::id (s/int-in 0 40)) ; just for testing purposes
(s/def ::name string?)
(s/def ::user (s/and (s/keys :req-un [::id ::name])))
(s/def ::user-list (s/and
                       (s/coll-of ::user :distinct true :into [])
                       #(if (empty? %) true (apply distinct? (mapv :id %)))))

(deftest so-test
    (let [users [{:id 11 :name "Jessica"} {:id 11 :name "Erica"}]]
        (prn (g/generate (s/gen ::user-list)))
        (s/assert ::user-list users)))