Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support :fn args #6

Open
danielcompton opened this issue Feb 27, 2019 · 3 comments
Open

Support :fn args #6

danielcompton opened this issue Feb 27, 2019 · 3 comments

Comments

@danielcompton
Copy link
Owner

No description provided.

@lucascs
Copy link

lucascs commented Apr 1, 2019

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
Copy link

lucascs commented Apr 1, 2019

(Great job on the lib BTW! =))

@holyjak
Copy link

holyjak commented May 23, 2019

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants