Skip to content

Instantly share code, notes, and snippets.

@jcromartie
Created December 13, 2010 00:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jcromartie/738505 to your computer and use it in GitHub Desktop.
Save jcromartie/738505 to your computer and use it in GitHub Desktop.
(defn dot-points
"Return a seq of points that would be good places to print a progress dot when doing n things"
[n]
(map first
(partition (inc (int (/ n 10)))
(range n))))
(defn map-progress
[f coll]
(let [n (count coll)
dot-set (set (dot-points n))
progress (atom 0)]
(map
(fn [x]
(when (dot-set @progress)
(print ".")
(.flush *out*))
(swap! progress inc)
;; and finally
(f x))
coll)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment