Fork me on GitHub
#clojure-spec
<
2022-10-01
>
Niclas15:10:16

Does anybody know of a lib that allows me to inline fn specs in the fn’s metadata? Looking for something like:

(defn myfn
  {:spec (...)}
  ...)
… which would be equivalent to:
(defn myfn ...)

(s/fdef myfn ...)

teodorlu15:10:15

I don't know of a library that does this specifically, but I think it should be doable with a macro. Perhaps something like this:

;; idea: create a macro defn+spec

(defn+spec myfn
  {:spec (,,,)}
  []
  ,,,)

;; so that it expands to

(do
  (defn myfn
    {:spec (,,,)}
    []
    ,,,)

  (s/fdef myfn (:spec (meta #'myfn))))

colinkahn01:10:46

There's https://github.com/danielcompton/defn-spec which has links to some other libs too in the README

👍 1