Fork me on GitHub
#clojure-spec
<
2018-11-23
>
rgm00:11:22

is there a way to fspec that, say, 250+ functions all conform to the same shape? (Apologies if this is in the docs; my scanning and google-fu don’t quite know how to phrase my question quite right).

rgm00:11:54

I guess I want something like (s/fdef-and-register-a-name ::function-shape ,,,)

rgm00:11:32

and then loop over all my function names as (s/fdef-by-name my-var ::function-shape)

rgm00:11:47

or maybe it’s just (map #(apply s/fdef % common-shape) ('my 'coll 'of 'function 'names))

rgm00:11:56

(nvm, I think I just rolled my own)

rgm00:11:31

(assuming common-shape is just '(:args ,,, :ret ,,, :fn ,,,) )

rgm00:11:18

(argh, s/fdef is a macro not a fn)

taylor01:11:47

@rgm maybe something like this would work:

(s/def ::fn-spec
  (s/fspec :args (s/cat :x number?)
           :ret number?))
(defn foo [x] (inc x))
(defn bar [x] (dec x))
(defmacro fdef-many [syms spec]
  `(do ~@(map #(list 'clojure.spec.alpha/def % spec) syms)))
(fdef-many [foo bar] ::fn-spec)
(st/instrument)
FWIW I think upcoming spec changes will make this easier

rgm02:11:09

Oh neat, thanks. I’ll give that a go.