Can I separate function definition (with defn) and schema (with fdef) into different namespaces?
yes, you can register functional spec using resolvable symbol, either fully qualified or aliased
That's great, thanks !
Take a look at next.jdbc for an example of specs in one namespace, but function definitions in another (so they're optional for users).
How to spec (with fdef) multi-arity functions? https://clojure.org/guides/learn/functions#_multi_arity_functions
UPD: it's described in fdef docs:
:args A regex spec for the function arguments as they were a list to be
passed to apply - in this way, a single spec can handle functions with
multiple arities
So, looks like we should use one schema to describe all arities at onceI spec them like this:
(s/fdef foo
:args (s/alt :ar1 (s/cat :arg1 ::my-spec)
:ar2 (s/cat :arg1 ::my-spec
:arg2 ::my-other-spec)
…
:ret …)
Where I usually use the argument names instead of "arg1" etc. for clarity.Correct
@gr.evocatus Obligatory shameless plug – https://github.com/fulcrologic/guardrails?tab=readme-ov-file#nested-specs. See also the https://github.com/fulcrologic/guardrails?tab=readme-ov-file#gspec-advantages and https://github.com/gnl/ghostwheel.specs/blob/master/src/ghostwheel/specs/clojure/core.cljc, if interested.