I have a function that I'd like to run multiple times, generating a list of the results:
(take 10 (repeatedly #(myfunc)))
I realized I could run them in parallel with pmap:
(pmap (fn [_] (myfunc)) (range 10))
But it is a bit untidy. Is there a standard function that lets me do this Something like:
(prun 10 #(myfunc))
?
You may also be interested in The Claypoole library for managing threadpools and parallel processing. Look at their version of pmap and pfor.
I don't think there's an existing function, but using pcalls rather than pmap seems a little closer to what you want:
(defn prun [n f]
(apply pcalls (repeat n f)))
You don't need to wrap myfunc with #() in the call torepeatedly, btw, nor calling prun as defined above:
(prun 10 myfunc)
You may find pvalues useful as well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With