As Daniel pointed out, this could probably be done more idiomatically (and 
functionally) using sequence functions. Here is a quick shot at a rewrite 
without any atoms or mutable state in the same number of lines of code (18) 
as your original example. If some of the intermediate lazy sequences cause 
any noticeable performance slow-down, you could switch over to transducers 
pretty easily.

(defn find-db-records-seq [db min-time max-time]
  (->> min-time
       (iterate #(plus-minutes % 30))
       (take-while #(before? % max-time))
       (partition 2 1 [max-time])
       (reduce (fn [{:keys [num-processed records]} [min-t max-t]]
                 (let [results (jdbc/query db
                                           ["select id, a, b, c from 
sometable where t > ? and t <= ? order by t"
                                            min-t max-t])]
                   {:num-processed (+ num-processed (count results))
                    :records (into records
                                   (mapcat (fn [rows]
                                             (let [foo (make-foo rows)]
                                               (->> rows
                                                    (filter (fn [{:keys [a b
]}] (relevant-record? foo a b)))
                                                    (map (fn [{:keys [id a 
b c]}] {:id id :a a :d (compute-d a b c)})))))
                                           (partition-all 200 results)))}))
               {:num-processed 0 :records []})))


Happy hacking!
  Gary

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to