Fork me on GitHub
#clojure-spec
<
2021-06-03
>
Braden Shepherdson18:06:34

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.

Braden Shepherdson18:06:32

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

Braden Shepherdson18:06:34

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

sgepigon18:06:40

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.