请注意,这特别是一个与spec-alpha2的问题
我们将使用教程中多规格示例的例子
(spec2/def :event/type keyword?)
(spec2/def :event/timestamp int?)
(spec2/def :search/url string?)
(spec2/def :error/message string?)
(spec2/def :error/code int?)
(defmulti event-type :event/type)
(defmethod event-type :event/search [_]
(spec2/keys :req [:event/type :event/timestamp :search/url]))
(defmethod event-type :event/error [_]
(spec2/keys :req [:event/type :event/timestamp :error/message :error/code]))
(spec2/def :event/event (spec2/multi-spec event-type :event/type))
;; ⇒ works as expected
(spec2/def :event/event (spec2/multi-spec event-type (fn [val tag] (assoc val :event/type tag))))
;; throws no impl of conform* for PersistentList
;; test case
(gen/sample (spec2/gen :event/event))
本质上看来,spec2还不能处理re-tag函数,这导致无法对新简单地图以外的任何内容进行规格控制,这很遗憾。