Fork me on GitHub
#clojure-spec
<
2018-08-01
>
tianshu04:08:37

Hi, how can I write a spec for arguments like [name & opts], opts is a hash-map here, I already have a ::opts spec for a hash-map, what a spec looks like for this function?

tianshu04:08:41

It's likely I can use (s/cat :name ::name :opts (s/keys* :req-un [...]))

tianshu04:08:07

but If I do (s/def ::opts (s/keys* ...)), I can't use ::opts here. It requires me to provide a vector

tianshu05:08:42

oh, my mistake, if I use s/keys* it's ok, but can't use (s/and (s/keys* ...) (...)).

athos07:08:10

(s/& (s/keys* ...) (...)) doesn’t work?

arohner17:08:09

If I have a multi-spec, what’s the best way to get an instance of a single dispatch value? Occasionally (-> (s/spec ::foo) (s/gen) (gen/such-that [f] (= :bar (:type f)) will “couldn’t satisfy such-that”

arohner17:08:23

but if I call the multimethod directly, it can return nonsense values, because (defmethod :foo [_] (s/keys :req-un [::type])), the :type doesn’t necessarily match :foo