Fork me on GitHub
#clojure-spec
<
2019-05-16
>
robertfw20:05:25

I'm trying to create an fdef :args spec for a multi-arity function in the general form of (defn my-func ([x] (my-func x nil)) ([x y] (do-thing x y))) I have a handful more args than just x & y, and don't want to repeat myself, so my first thought was to do something like (def base-args [:x ::my-x-spec]) (s/fdef my-func :args (s/alt :without-y (apply s/cat base-args) :with-y (apply s/cat (conj base-args :y ::my-y-spec))) - but alas, s/cat is a macro so I can't do that. I've had another peruse of the spec docs but nothing jumped out at me. any suggestions?

robertfw20:05:39

Can I make an (s/cat base-args) and then append onto it somehow?

robertfw20:05:45

I understand that I can just provide a full list of [:x ::my-x :y ::my-y], but I'd like to be able to generate examples of each arity

Alex Miller (Clojure team)20:05:02

Just build a single s/cat with nested optional additional args with s/?

Alex Miller (Clojure team)20:05:07

Or you could build each arity as an s/cat that combined the prior with an additional arg

robertfw21:05:57

Thanks, I'll look at those options