Using MapIndexed
, which also gives you the index of the element in the list instead of Map
would be very convenient. That way, you can set up a Print
or a PrintTemporary
cell. For example:
Clear[f]
f = (Pause[0.2]; PrintTemporary[First@#2]; #^2) &; (* your complicated function *)
MapIndexed[f, Range[10]]
(* 1
2
...
...
{1, 4, 9, 16, 25, 36, 49, 64, 81, 100} *)
With a PrintTemporary
cell, it prints all the output, but the cell disappears when the evaluation is complete, saving you the trouble of cleaning the mess.
You can also print directly to the messages notebook using the PrintToConsole
function from my answer heremy answer here. This keeps your current working notebook clean and you can always check in the other to see the progress.
Another option is to use side-effects and increment a variable, which allows you to use Monitor
. For example:
Clear[g]
g = (Pause[0.2]; i = First@#2 + 1; #^2) &;
Block[{i = 1}, Monitor[MapIndexed[g, Range[10]], i]]
See this answerthis answer by Brett Champion for the different ways in which you can create a progress bar to suit your needs.