-
Notifications
You must be signed in to change notification settings - Fork 25
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 per-arity :args
and :fn
specs
#14
Comments
@alexandergunnarson Thanks for the ticket and I'm glad you're liking Orchestra. I haven't tried it yet, but try giving Clojure's normal This is how orchestra/test/cljc/orchestra/core_test.cljc Lines 35 to 38 in e629615
EDIT: On second thought, you mean per-arity EDIT 2: I gave user=> (require '[orchestra.core :refer [defn-spec]])
nil
user=> (defn-spec my-abs pos-int? [n integer?] {:pre [(zero? n)]} (if (< n 0) (- n) n))
user/my-abs
user=> (my-abs 2)
java.lang.AssertionError: Assert failed: (zero? n) |
Thanks for your quick reply @jeaye! Yes, my actual use case is structurally similar to my example, the most important part being
That takes care of the arity-specific Maybe this is outside the scope of Orchestra as you suggest, but for me it's a pretty essential addition if I'm to use |
Still interested in this feature — what are your thoughts @jeaye? |
Thanks for the ping. I see the use in this, but it's not something I can make time to implement right now, since it's not something I would use. If you or someone else were to implement it, I think it would have to be different from your original suggested syntax, since what you suggested is ambiguous for empty fn definitions (does it return a map or is that map specifying The syntax which would work, I think, would be to use the existing meta map already supported in (defn-spec sym whole-fn-ret-spec
{:arity {2 {:pre (s/and a b) ; to be `s/and`ed to the other arity-specific `:args` specs
:post ((if a number? string?) %)}}} ; arity-specific `:fn` spec
([a arg-spec-a, b arg-spec-b]
...)) That way Clojure can still have its own Let me know if that suggestion suits all of your needs. |
No problem! And I see what you're saying — I've never liked the :pre and :post syntax for that reason. I prefer the following syntax: (defn-spec sym whole-fn-ret-spec
([a arg-spec-a, b arg-spec-b & args | (s/and a b args) > #((if a number? string?) %)]
...)) The In either case I understand you don't have time to implement it. Once we hammer out the syntax, I could conceivably make the time for it. |
This is done in https://github.com/alexandergunnarson/defnt. |
I've just read through the docs you have for defnt, @alexandergunnarson. Nice work! As for its intersection with Orchestra, if you're up for making a PR, please do! Ideally we don't have too many of these |
Thanks so much for taking the time to do that @jeaye! I appreciate your positive feedback :) And ideally, yes haha, we'd just have one. I'm not sure about PR'ing it, though, as then a significant chunk of code will have to be maintained in two places. As I see it there are four options, in decreasing order of my preference:
What do you think? |
First of all, Orchestra is great! It's extremely useful, and employs some ideas that are similar to what I'm currently pursuing in one of my libraries.
One feature set I would love to see is to be able to add
:args
and:fn
validation on a per-arity basis:What do you think about this?
The text was updated successfully, but these errors were encountered: