Share your thoughts in the 2021 Clojure Community Survey!

Welcome! Please see the About page for a little more info on how this works.

0 votes
in Spec by

NB this is specifically a problem with spec-alpha2

We'll use the example from the multi-spec example from the tutorial:

(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))

Essentially looks like spec2 can't handle retag functions yet, which makes it impossible to spec anything beyond simple maps, sadly.

1 Answer

0 votes
by

Yeah, we're still thinking about what to do about this wrt symbolic specs.

...