defn-spec icon indicating copy to clipboard operation
defn-spec copied to clipboard

Support :fn args

Open danielcompton opened this issue 6 years ago • 3 comments

danielcompton avatar Feb 27 '19 08:02 danielcompton

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

lucascs avatar Apr 01 '19 19:04 lucascs

(Great job on the lib BTW! =))

lucascs avatar Apr 01 '19 19:04 lucascs

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?

holyjak avatar May 23 '19 06:05 holyjak