i'm looking to write a spec that checks a list of tuples to see if there's 0 or 1 tuple that starts with some value
i have the spec that verifies and conforms that the shape is correct:
(s/def ::handler-clause (s/cat :name (s/nonconforming
(s/or :keyword keyword?
:class symbol?))
:arglist vector?
:body (s/* any?)))
and then in the fdef
i have (s/* (s/spec ::handler-clause))
for that argument
inputs look like [:error [& args] (println args)]
or [:no-error [& args] args]
*
means 0 or more, not 0 or 1
?
is for 0 or 1
my apologies, i mean, i'd like to have it check that there is any number of tuples that don't start with :no-error
and 0 or 1 tuples that start with :no-error
so something like
(s/fdef handler-case
:args (s/cat :expr any?
:bindings (s/and (s/? (s/cat :name (s/and #(= :no-error %)
(s/nonconforming
(s/or :keyword keyword?
:class symbol?)))
:arglist vector?
:body (s/* any?)))
(s/* (s/cat :name (s/and #(not= :no-error %)
(s/nonconforming
(s/or :keyword keyword?
:class symbol?)))
:arglist vector?
:body (s/* any?)))
)))