【发布时间】:2017-07-09 20:11:08
【问题描述】:
使用 clojure.spec,有没有办法为嵌套地图定义更“人类可读”的规范?以下内容读起来不太好:
(s/def ::my-domain-entity (s/keys :req-un [:a :b])
(s/def :a (s/keys :req-un [:c :d]))
(s/def :b boolean?)
(s/def :c number?)
(s/def :d string?)
鉴于符合实体的形状类似于
{:a {:c 1 :d "hello"} :b false}
我的抱怨是,如果规范有任何类型的嵌套映射或任何深层结构,阅读规范就会变得困难(呃)……因为您在文件中上下移动键,而它们不是“就地”声明.
为了比较,类似 schema 的东西允许更易读的嵌套语法,紧密反映实际数据形状:
(m/defschema my-domain-entity {:a {:c sc/number :d sc/string} :b sc/bool})
这可以在 clojure.spec 中完成吗?
【问题讨论】:
标签: clojure clojure.spec