Created
January 25, 2024 07:52
-
-
Save igrishaev/c9ab0594cce2e50738c7a1083a320f5a to your computer and use it in GitHub Desktop.
This file contains 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 pmap+ | |
" | |
Like pmap but accepts a custom size of a parallel | |
window. Not lazy, returns a vector. Takes only | |
one collection of arguments at the moment. | |
" | |
[n func items] | |
(lazy-seq | |
(let [[head tail] | |
(split-at n items)] | |
(when (seq head) | |
(let [futures | |
(for [item head] | |
(future (func item)))] | |
(concat | |
(->> futures | |
doall | |
(map deref)) | |
(pmap+ n func tail)))))) | |
#_ | |
(loop [result [] | |
items items] | |
(let [[head tail] (split-at n items)] | |
(if (seq head) | |
(let [futures | |
(for [item head] | |
(future (func item)))] | |
(recur (->> futures | |
doall | |
(mapv deref) | |
(into result)) | |
tail)) | |
result)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment