This function works, but I am involved in the learning process of Clojure and want to know if there is a better / cleaner way to write this:
;; loop over methods, update the scripts map, and return scripts
(defn update-scripts
[filename]
(loop [scripts {}
methods (get-methods filename)]
(if (seq methods)
(let [method (first methods)
sig (get-method-signature method)
name (get-method-name sig)]
(recur (assoc scripts name {:sig sig, :method method})
(rest methods)))
scripts)))
(update-scripts "gremlin.groovy")
UPDATE: this is what I ended up using:
(defn- update-scripts
[scripts method]
(let [sig (get-method-signature method)
name (get-method-name sig)]
(assoc scripts name {:sig sig :method method})))
(defn get-scripts
[filename]
(reduce update-scripts {} (get-methods filename)))
source
share