Fork me on GitHub
#clojure-spec
<
2018-05-14
>
Oliver George05:05:24

Bit of a thought bubble but how about using spec's generative features to do "type checking" like behaviour in the IDE: https://gist.github.com/olivergeorge/584b54fe0b1d4c6ce3c7a44ee8c29095

gklijs06:05:46

Should be doable at least with cursive I think, it already has a check for having the correct arity.

jmayaalv13:05:42

what’s the best way to get the keys descriptions for a s/keys :req) form? calling (s/describe) returns a (keys) but not sure how can it be used.

jmayaalv14:05:12

got it. managed to do what i wanted this way:

(s/def :clecto/person (s/keys :req [:clecto.person/first-name :clecto.person/last-name]))
(apply hash-map (rest (s/form :clecto/person)))
user> {:req [:clecto.person/first-name :clecto.person/last-name]}

jimbob23:05:51

How can i check against a collection that only certain values of maps in the collection are unique? i.e. that the collection of maps is valid iff all maps in the collection have distinct values for at least one of two fields. ex:

[{:unique-field "abc" :a 1 {unique-field2 "abc2"} {:unique-field "abc" :a 3 {unique-field2 "abc2"}]
does not pass validation but
[{:unique-field "abc1" :a 1 {unique-field2 "abc2"} {:unique-field "abc" :a 3 {unique-field2 "abc2"}]
does

nenadalm04:05:40

your datastructures are not valid (parenthesis do not match)

guy09:05:47

I think you would write a spec that for those values would have to be unique

guy09:05:28

(s/def :a/unique-field #{"unique 1" "unique2"})

guy09:05:56

so then the spec for that map would include that field and that spec above and would only allow those values

guy09:05:27

Or do you mean the maps are only valid when, regardless of the values, they have to all be unique?

jimbob15:05:35

the first one yes.