Clojure progress reporting on sequence

/ Published in: Clojure
Save to your folder(s)

Copy this code and paste it in your HTML
  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


RSS Icon Subscribe to comments

You need to login to post a comment.