Posted By

yairiny on 02/07/11


Tagged


Versions (?)

Clojure progress reporting on sequence


 / Published in: Clojure
 

  1. (defn seq-counter
  2. "calls callback after every n'th entry in sequence is evaluated.
  3. Optionally takes another callback to call once the seq is fully evaluated."
  4. ([sequence n callback]
  5. (map #(do (if (= (rem %1 n) 0) (callback)) %2) (iterate inc 1) sequence))
  6. ([sequence n callback finished-callback]
  7. (drop-last (lazy-cat (seq-counter sequence n callback)
  8. (lazy-seq (cons (finished-callback) ()))))))

Report this snippet  

You need to login to post a comment.