请注意,这特别是一个与spec-alpha2相关的问题
我们将使用教程中的多spec示例
(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还不能处理retag函数,这导致无法对简单映射以外的任何东西进行spec,遗憾的是。