Skip to content

Instantly share code, notes, and snippets.

@timcharper
Created June 10, 2010 23: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 timcharper/433817 to your computer and use it in GitHub Desktop.
Save timcharper/433817 to your computer and use it in GitHub Desktop.
(defn map-queue
"Like map, but populated eagerly via fill-queue
(map-queue odd? (range 1 10) :queue-size 5) ;; will always calculate 5 ahead of the last used item from the lazy sequence"
[f coll & options]
(apply fill-queue (fn [fill] (doseq [value coll] (fill (f value)))) options))
(defn pmap-queue
"map-queue in parallel (using futures)
(pmap-queue odd? (range 1 10) :queue-size 5)"
[f coll & options]
(map deref (apply map-queue #(future (f %)) coll options)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment