在我的 Clojure 项目中,我有这些:
:dependencies [
[org.clojure/clojure "1.8.0"]
[prismatic/schema "1.0.5"]]
这被认为是有效的:
(require '[schema.core :as s])
(def pos (s/pred #(re-matches #"\d+,\d+" %)))
(s/validate pos "0,0")
; "0,0"
因此,基于此,我认为以下内容也是有效的(但事实并非如此):
(require '[schema.core :as s])
(def pos (s/pred #(re-matches #"\d+,\d+" %)))
(def structure {(s/optional-key pos) s/Any})
(s/validate structure {"0,0" true, "2,0" false})
; Value does not match schema: {"0,0" disallowed-key, "2,0" disallowed-key}