Fork me on GitHub

Let's say I have a strange function that has two arities: 1-arity computes some results and returns them 2-arity uses 1-arity to compute the same results and save the output to file. How can I write :ret spec for this? I tried :fn but struggling with reusing an existing spec

:fn (s/or :results (s/and #(= 1 (-> % :args count))
                  :ouput-in-file (s/and #(= 2 (-> % :args count))
                                        #(-> % :ret empty?))))

Here, the ::result-spec isn't properly used - I need to apply it only to the :ret key value, not the whole map passed to :fn.


if it were me I'd have two different functions


That was my idea too, but let's say it's a "convention" to do it this way. Can I still somehow reuse the ::result-spec or is there a better way to write :ret spec for this function?


(s/def ::ret ::result-spec) (s/and ... (s/keys :req-un [::ret]))


Nice, thanks! I guess the only problem would be if I had more than one such function in the same ns (conflicting ::ret specs) but that's not an issue in my case.