clojure-spec

Ben Sless 2021-12-14T11:04:53.247300Z

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?

jkxyz 2021-12-14T12:06:50.248200Z

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 Sless 2021-12-14T15:33:51.248400Z

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

jkxyz 2021-12-14T16:39:00.248600Z

You could use conformer to tag each branch

jkxyz 2021-12-14T17:01:10.248800Z

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

jkxyz 2021-12-14T17:05:55.249Z

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