Clojure “的表达方式;“集合中的成员”;有着丰富的图式
我想写一个模式,其中数据结构中的元素e可以是一组项中的任意成员;E∈ 美国的Clojure规范使用如下集合表示:Clojure “的表达方式;“集合中的成员”;有着丰富的图式,clojure,plumatic-schema,Clojure,Plumatic Schema,我想写一个模式,其中数据结构中的元素e可以是一组项中的任意成员;E∈ 美国的Clojure规范使用如下集合表示: (spec/def ::key-set #{:subprocess :leiningen :nrepl}) (gen/sample (spec/gen ::key-set)) ; => (:nrepl :subprocess :subprocess :leiningen :subprocess :nrepl :subprocess :leiningen :nrepl :subp
(spec/def ::key-set #{:subprocess :leiningen :nrepl})
(gen/sample (spec/gen ::key-set))
; => (:nrepl :subprocess :subprocess :leiningen :subprocess :nrepl :subprocess :leiningen :nrepl :subprocess)
对于一组关键字
然而,在模式中,集合用于表示一组事物,而不是集合中的一个元素成员。那么,我如何在模式中表示我想要一个集合中的一个成员呢
user=> (schema.core/validate (schema.core/enum "a" "b" "c") "a")
"a"
=> (schema.core/validate (schema.core/enum "a" "b" "c") "z")
clojure.lang.ExceptionInfo: Value does not match schema: (not (#{"a" "b" "c"} "z"))
schema.core/enum
就是您要寻找的
user=> (schema.core/validate (schema.core/enum "a" "b" "c") "a")
"a"
=> (schema.core/validate (schema.core/enum "a" "b" "c") "z")
clojure.lang.ExceptionInfo: Value does not match schema: (not (#{"a" "b" "c"} "z"))