Fork me on GitHub
#clojure-spec
<
2016-09-27
>
kurt-yagram12:09:02

how to s/fdef functions with optional named args?

(s/fdef myfun 
  :args (s/cat :first string? <???>))
(defn myfun "" [first & {:keys [named]}]
   ...)
so what should be at <???> to add a spec for the named argument?

madstap12:09:02

(s/? (s/cat :named-k #{:named} :named boolean?))

kurt-yagram12:09:48

Got it. Makes sense.

Alex Miller (Clojure team)14:09:25

no, don’t do that - this is what s/keys* is for

Alex Miller (Clojure team)14:09:45

(s/def ::named boolean?)
(s/fdef myfun :args (s/cat :first string? :opts (s/keys* :req-un [::named])))

Alex Miller (Clojure team)14:09:17

this allows you to specify any number of kwarg options at the end in any order

madstap15:09:20

Right, I had missed s/keys*, thanks for the clarification. Sometimes it seems like you guys think of everything, probably all that hammock time.

kurt-yagram15:09:12

ah, ok... thanks!