Fork me on GitHub
#clojure-spec
<
2021-12-14
>
Ben Sless11:12:53

With multi specs, unlike with or I can't get back the matching case when calling conform. What should I do in case I want to take actions based on the spec the input matches?

jkxyz12:12:50

You can use whatever dispatch function you use for the multi-spec to also branch in other parts of the code. The obvious case is a :type key or something similar

Ben Sless15:12:51

I was hoping I wouldn't need to retread this path because I considered it an implementation detail

jkxyz16:12:00

You could use conformer to tag each branch

jkxyz17:12:10

If it's a closed set of branches you can use or with a predicate that matches on the "type" -- which I suppose is probably the reason that multi-specs don't conform with a tag. If you're trying to parse a structure against an open set of branches you could end up with any value as the tag, so you'd need another multimethod to dispatch to code which handles the conformed values. If you don't expect consumers of the namespace to extend the spec I'd say just use or

jkxyz17:12:55

If it really is just an implementation detail then I'd say use conformer to conform to some useful value