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
benny 2021-01-05T23:02:16.032600Z

is it possible to write specs for maps like you can in schema?

(def User
  {::id   s/Int
   ::name s/Str})
vs
(s/def ::id int?)
(s/def ::name string?)
(s/def ::user
  (s/keys :req [::id ::name]))

alexmiller 2021-01-05T23:08:23.032800Z

that is how you do it in spec

benny 2021-01-05T23:13:29.033100Z

there’s no way to do it inline like schema?

alexmiller 2021-01-05T23:22:24.033300Z

no, there is a philosophical difference in approach here

alexmiller 2021-01-05T23:23:16.033500Z

spec is trying to build a registry of spec'ed attributes. the attributes are seen as primary, the map only as container.

3
alexmiller 2021-01-05T23:23:56.033700Z

spec 2 is developing this further and will have some support for unqualified attributes with inline specs in a schema

🆒 1