clojure-spec

Niclas 2022-10-01T15:27:16.670529Z

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 ...)

teodorlu 2022-10-01T15:55:15.386519Z

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))))

2022-10-02T01:30:46.456919Z

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

👍 1