clojure - logging within map or reduce -


i have following function

(defn save-des-to-db [f]     (->> f         java.io.file.         file-seq         rest         (map (juxt get-bp-name #(.getcanonicalpath %)))         (map get-des)         (map add-bp-des-to-db)         )) 

works ok i'd see progress each "map" processes large folder.

is there map-with-println or map-with-log function can use? right way go this.

the purpose of map transform sequence applying function every item. lazy, means it's not guaranteed apply function until need given item. in case you're not doing sequence, there's no guarantee elements saved. therefore function should not called save-des-to-db, more appropriate name build-des-records. leave out add-bp-des-to-db part, , write (perhaps in different function):

(doseq [f folders]    (println "adding folder" f)    (add-bp-des-to-db f)) 

doseq executes body repeatedly, side effects. (see link doseq, dorun , doall in edbond's comment)


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -