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

clojure.spec :fn equivalent? #764

Closed
knubie opened this issue Oct 15, 2022 · 5 comments
Closed

clojure.spec :fn equivalent? #764

knubie opened this issue Oct 15, 2022 · 5 comments
Labels
enhancement New feature or request

Comments

@knubie
Copy link

knubie commented Oct 15, 2022

In clojure.spec you can do something like this:

(s/fdef ranged-rand
  :args (s/and (s/cat :start int? :end int?)
               #(< (:start %) (:end %)))
  :ret int?
  :fn (s/and #(>= (:ret %) (-> % :args :start))
             #(< (:ret %) (-> % :args :end))))

Where the :fn can be used to verify the relationship between args and return value.

Is there any way to do this in malli?

@ikitommi
Copy link
Member

No, there is not yet such a thing, but it would be easy to add. Interested in doing a PR for that?

@ikitommi ikitommi added the enhancement New feature or request label Oct 16, 2022
@knubie
Copy link
Author

knubie commented Oct 17, 2022

Well, if it's easy, then yeah I can give it a shot. 😎 I'll admit I haven't looked at the source code. Can you give me any pointers on where to start?

@ikitommi
Copy link
Member

You could start from malli.core/-instrument. It's the (pure) functional core behind the functions schemas, everything else builds on top of that.

@ikitommi
Copy link
Member

@ikitommi
Copy link
Member

fixed in #1000

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

No branches or pull requests

2 participants