clojure-spec 2022-09-26

Curious - why does the Spec form for s/double-in return a s/and with a series of predicates attached for each option passed (e.g., :min, :max, etc), and something like s/every does not include the https://github.com/clojure/spec.alpha/blob/13bf36628eb02904155d0bf0d140f591783c51af/src/main/clojure/clojure/spec/alpha.clj#L558-L567?

(s/form (s/double-in :min 2))
=> (clojure.spec.alpha/and clojure.core/double? (clojure.core/fn [%] (clojure.core/<= 2 %)))
(s/form (s/every string? :min-count 2))
=> (clojure.spec.alpha/every clojure.core/string? :min-count 2)  

Alex Miller (Clojure team) 2022-09-26T19:18:18.127369Z

This is a limitation of how double-in is written as a composite but without custom form support. This has actually been addressed in spec 2 (not sure if this particular one has been fixed there but it could be)

Ok. So the desired output for s/double-in's (and its ilk) form would be similar to that of s/every -- returning the kv options passed to the form instead of the composite?

Alex Miller (Clojure team) 2022-09-26T19:33:14.425229Z

yep, I think the s/form should reproduce the original not expose how it's implemented

Alex Miller (Clojure team) 2022-09-26T19:34:00.938869Z

spec-alpha2 % clj
Clojure 1.10.1
user=> (require '[clojure.alpha.spec :as s])
nil
user=> (s/form (s/double-in :min 2))
(clojure.alpha.spec/double-in :min 2)

👍🏻 1

Makes sense. Thanks for the response.