Fork me on GitHub
#schema
<
2018-04-23
>
ben.mumford15:04:40

hi all, i have a value and i want to check it is a map which can have any values except a specific few. how best to do this?

ben.mumford15:04:15

something knarly like this: (s/pred #(and (map? %) (empty? (some #{:a :b} (keys %)))))

tanzoniteblack17:04:20

@ben.mumford620 I probably would implement it with constrained:

(schema/constrained {schema/Any schema/Any}
                    (fn [m]
                      (empty? (clojure.set/intersection (set (keys m))
                                                        #{:alpha :beta})))
                    "Can't contain certain keys")

tanzoniteblack17:04:12

the actual function checking for certain keys could of course be done with some like you did instead of intersection