Created
December 13, 2010 00:41
-
-
Save jcromartie/738505 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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