clojure-spec

About: http://clojure.org/about/spec Guide: http://clojure.org/guides/spec API: https://clojure.github.io/spec.alpha/clojure.spec.alpha-api.html
2020-05-07T22:43:13.325Z

is there any way to abstract a spec?

(defmacro to-many-ref-type
 [spec]
 `(s/coll-of (s/or :id u/id? :ident ::ident ~(keyword (name spec)) ~spec) :type vector?)))

(s/def :habit/tasks (to-many-ref-type ::task))
i'm trying this, but I think the macroexpansion of s/def doesn't like it

2020-05-07T22:45:25.325400Z

actually, i think it's working - my issue is it's not working in cljs, I'll dig into it

aisamu 2020-05-09T19:17:50.325700Z

CLJS macros can be a bit finicky! Check https://code.thheller.com/blog/shadow-cljs/2019/10/12/clojurescript-macros.html

2020-05-09T19:22:50.326Z

That was my issue! I was trying to use a cljc file and updated them to separate cljs and clj files. it's working now 🙂

👍 1