6

If we have a procedural construct like a Do loop or Table, it is straightforward to make a progress bar to indicate the percent completion of the task. For example:

f[k_] := RandomInteger[{-k, k}, 1000000];
ProgressIndicator[Dynamic[k/100]]
Do[f[k], {k, Range[100]}]

Replacing Do by Table works as well. But I have grown fond of the "functional style" using Map:

f[#]& /@ Range[100]

Is there a way to make a progress indicator that works with this style of iteration?

m_goldberg
  • 107,779
  • 16
  • 103
  • 257
bill s
  • 68,936
  • 4
  • 101
  • 191

1 Answers1

4

You can include an iterator along with the function in the mapping:

k = 0; (++k; f[#]) & /@ Range[100];
m_goldberg
  • 107,779
  • 16
  • 103
  • 257
Kuba
  • 136,707
  • 13
  • 279
  • 740