danielcompton/defn-spec

Support :fn args

danielcompton opened this issue · 3 comments

Support :fn args

what about using metas for that?

(ds/defn ^::ds/fn (fn [{:keys [args ret]}] (> ret (first args)))
  increment :- int? 
  [x :- int?] 
  (inc x))

or even use a conditions-map syntax:

(ds/defn increment :- int? [x :- int?] 
  {:fn (fn [{:keys [args ret]}] (> ret (first args)))}
  (inc x))

(Great job on the lib BTW! =))

I think using metas is a good idea. Orchestra does the same:

; :fn specs can be specified using the fn's meta map.
(defn-spec my-abs number?
  {:fn #(= (:ret %) (-> % :args :n))}
  [n number?]
  (Math/abs n))

@danielcompton I am really missing this feature as it forces me to duplicate fn specs with fdef in my test namespace so that I could check them with clojure.spec.test.alpha/check. What do you think about adding them via metadata? Would you be interested in a PR?