Suppose you have a bunch of computations, which you want to execute using foreach. Perhaps you want to parallelize them, now or in the future. Each computation returns a single number. What is the best idiom to obtain the mean of all the numbers computed in this fashion?
I have two solutions in mind, which I’ll post as possible answers so that you can vote and comment on these individually, and perhaps even edit them to improve them. But I guess there might be even better ways, so additional answers are welcome. My answers will include examples which you can adopt to demonstrate your own techniques.
One solution accumulates the results in a vector, and eventually executes the
meanfunction on that.Benefits:
foreachcalls as wellmeanas wellDrawbacks: