clojure-spec

About: http://clojure.org/about/spec Guide: http://clojure.org/guides/spec API: https://clojure.github.io/spec.alpha/clojure.spec.alpha-api.html
2021-06-03T18:04:34.052200Z

I'm struggling with nesting s/cat calls. I've got a tuple-like thing, but it's not implemented by a real vector, rather by a deftype. so I originally wrote the spec for it with s/tuple but it failed to match. I switched to s/cat with the parts spelled out, and that works.

2021-06-03T18:05:32.053200Z

but then in a (s/fdef foo :args (s/cat :x ::tuple-like :y int?)) it fails, since the cats end up running together.

2021-06-03T18:06:34.054200Z

I guess I can always write the ::tuple-like predicate as an #(instance? TheDeftype %) but that seems really clunky.

sgepigon 2021-06-03T18:51:40.056300Z

Try wrapping it in a s/spec to prevent them running together: (s/cat :x (s/spec ::tuple-like) :y int?). Spec 1 does this with s/spec, spec 2 will do this with https://github.com/clojure/spec-alpha2/wiki/Differences-from-spec.alpha#nested-regex-contexts.