I should also mention that the s/alt one is fine too, but in general I find 
receiving the same conformed map in either case but with keys either 
present or absent works better with all your typical Clojure destructuring 
etc so I prefer the s/? version.

On Thursday, October 5, 2017 at 2:34:36 PM UTC-5, Alex Miller wrote:
>
>
>
> On Thursday, October 5, 2017 at 2:02:10 PM UTC-5, Peter Hull wrote:
>>
>> Is there any guidance on how to do the fdef for a function with more than 
>> one arity? As an example, this one which takes one or two arguments:
>>
>
> The regex specs can cover multiple options via ?, *, etc.
>  
>
>>
>> (defn report
>>   "Report an error code, optionally with a message"
>>   ([errno] ...)
>>   ([errno msg] ...))
>>
>>
> So you want:
>
> (s/fdef report
>   :args (s/cat :errno int? :msg (s/? string?)))
>  
>
>> Could be:
>> (s/fdef report
>>         :args (s/alt :brief (s/cat :errno integer?)
>>                      :full (s/cat :errno integer? :msg string?)))
>>
>> or:
>> (s/fdef report
>>         :args (s/cat :errno integer? :msg (s/? string?)))
>>
>>
>> Some options make more sense than others, depending on the function. For 
>> example clojure.core/map is defined with five separate arities but I don't 
>> think it would be right to spec it as an alt with five alternatives, since 
>> they are all covered by "function followed by zero or more colls"
>>
>> So, has a convention been established on how best to do it? 
>>
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to