Fork me on GitHub
#clojure-spec
<
2017-12-28
>
romni14:12:15

is there a way to spec a map using a coll of types/keywords (instead of a single type/keyword as with multi-spec)? the idea is that all specs corresponding to matched types are merged and used to validate the map

romni15:12:55

what i have is { ::types [:first :second] } and what i'm looking for is a way to create something like a multi-spec which dispatches on the values in the coll corresponding to ::types and which will build a spec like (s/merge ::first ::second)

souenzzo13:12:47

(defmulti types ::types) (defmethod types :default [{::keys[types]}]) (eval (apply s/merge types)))` Some lke this?

ikitommi15:12:19

Hi. I have a vector of s/keys specs and I would like to merge them, without eval. As s/merge is a macro, I guess I should use merge-spec-impl?

ikitommi19:12:52

I’m trying to combine stuff with s/merge. Is this intentional or a bug?

(s/explain any? {:x 1, :y 2})
; Success!

(s/explain (s/merge any?) {:x 1, :y 2})
; val: {:x 1, :y 2} fails predicate: any?

ikitommi19:12:59

ok, this works thou:

(s/explain (s/merge (s/spec any?)) {:x 1, :y 2})
; Success!

ikitommi20:12:43

But as the s/spec is macro too, with my arbitrary vector-of-specs input, I would have to call s/spec-impl instead to avoid eval and figure out the forms somehow. Any news on the new functional core for clojure.spec?