clojure-spec

Benjamin 2023-01-25T11:06:37.222099Z

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

Benjamin 2023-01-25T11:10:54.109589Z

(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

Benjamin 2023-01-25T11:11:48.636969Z

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

Alex Miller (Clojure team) 2023-01-25T13:13:49.520279Z

Yes, it would fail if that spec changed

Alex Miller (Clojure team) 2023-01-25T13:14:22.921789Z

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

Benjamin 2023-01-25T13:19:07.564749Z

Ok thanks!