Fork me on GitHub

Hi, I’m trying to figure out how to model this with spec. Say I have (s/def ::rule-type #{:rule1 :rule2}) I then want to create (s/def ::rule1 (s/keys ...), etc where aside from the keys that are selected ::rule-type is ‘narrowed’ to specific value, such that I can then have a ::rule spec that’s an or of those guys


might be what multi-spec is for?

Alex Miller (Clojure team)12:07:11

yes, seems like exactly what s/multi-spec is for


ah ok, actually just got it working with and s/and ‘passthru’ but will try the mult-spec as well


did this

(s/and (s/keys :req [::rule-type ::rule-id ::rule-action ::object-locator]
                            :opt [::load-order])
                     #(= (::rule-type %) :selection)))
but yeah multi-spec seems a bit more elegant spec2 looks exciting @alexmiller


It also gives much better feedback (more specific) when using with expound for instance

Alex Miller (Clojure team)13:07:05

s/multi-spec is also open so you can add more rules later


sweet. Hey is spec2 going to have fspec support for mutimethods?

Alex Miller (Clojure team)13:07:39

not something we're working on right now, but maybe eventually