Fork me on GitHub
#clojure-spec
<
2023-01-25
>
Benjamin11:01:37

Hi, I would like to extract a spec from a function spec (`s/fdef`). I realized since the spec is speccing an arglist this might be a bit challenging. Right now I wanted to extract the 2nd arg spec always. Context: https://github.com/WorksHub/leona/issues/4

Benjamin11:01:54

(defn droid-resolver [ctx query value])

(s/def ::int int?)
(s/def ::string string?)
(s/def ::any any?)

(s/fdef droid-resolver
  :args (s/cat :a ::int :b ::string :c ::any)
  :ret ::int)

(let [[_ _ _ _ b-spec]
      (s/form (:args (s/get-spec #'droid-resolver)))]
  b-spec)
:leona.core-test/string

Benjamin11:01:48

this would not fly would it? It would fail if someone defines a spec differently than cat ?

Alex Miller (Clojure team)13:01:49

Yes, it would fail if that spec changed

Alex Miller (Clojure team)13:01:22

There’s not really a way to get the spec of a specific arg like that