Fork me on GitHub
#clojure-spec
<
2017-06-10
>
stbgz14:06:26

thanks for the help @alexmiller

mikecarter16:06:42

if i have a person comprising of an id (int) and a name (string), how can i write a spec for a collection of people to ensure there are no duplicate IDs?

mikecarter16:06:25

@potetm would that catch [{:id 1 :name "Alex"} {:id 1 :name "Frank"}]?

potetm16:06:42

Something like (apply distinct? (map :id people)) would I think.

potetm16:06:48

(apply distinct? (map :id 
                      [{:id 1 :name "Alex"} 
                       {:id 1 :name "Frank"}]))
=> false
(apply distinct? (map :id 
                      [{:id 1 :name "Alex"} 
                       {:id 2 :name "Frank"}]))
=> true

mikecarter17:06:14

@potetm thanks! i’ll give it a go