Fork me on GitHub
#clojure-spec
<
2019-07-16
>
eoliphant12:07:10

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

gfredericks12:07:44

might be what multi-spec is for?

Alex Miller (Clojure team)12:07:11

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

eoliphant13:07:27

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

eoliphant13:07:13

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

jeroenvandijk13:07:42

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

eoliphant13:07:34

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