have defnav generate every method as a helper function as well (with name <name>-<method-name>, takes params as initial arguments followed by regular method arguments (except for 'this')

This commit is contained in:
Nathan Marz 2016-08-17 09:42:59 -04:00
parent a765d1af50
commit a35cacae67

View file

@ -255,9 +255,19 @@
(let [afn# (fn [~structure-sym] ~@impl)]
(i/filter-transform afn# structure# next-fn#)))))
(defn- helper-name [name method-name]
(symbol (str name "-" method-name)))
(defmacro defnav [name & body]
`(def ~name (nav ~@body)))
(defmacro defnav [name params & impls]
;; remove the "this" param for the helper
(let [helpers (for [[mname [_ & mparams] & mbody] impls]
`(defn ~(helper-name name mname) [~@params ~@mparams] ~@mbody))
decls (for [[mname & _] impls]
`(declare ~(helper-name name mname)))]
`(do
~@decls
~@helpers
(def ~name (nav ~params ~@impls)))))
(defmacro defcollector [name & body]
`(def ~name (collector ~@body)))