2
$\begingroup$

I am mapping a function across a list, but would like to pause before each item. For instance:

function[variable_]:=(
variable * 2
)
function/@{1,2,3}

would give me {2, 3, 6}

However, I would like for the function to pause before being mapped to the next variable, for instance, 1*2 (pause for let's say, 2 seconds), 2 *2 (pause for 2 seconds) 3 * 2 (pause for two seconds).

Is this at all possible?

$\endgroup$
5
  • 5
    $\begingroup$ There is a function called Pause that should do what you want. Just insert Pause[2]; in the definition of you function. $\endgroup$
    – TimRias
    Nov 19, 2017 at 20:02
  • $\begingroup$ Inserting Pause is probably not what you want. It will just increase the running time but you won't see how each element is calculated. $\endgroup$
    – halirutan
    Nov 19, 2017 at 22:36
  • $\begingroup$ you can use Print or maybe work with Monitor. Its not really clear exactly what you are trying to accomplish, $\endgroup$
    – george2079
    Nov 20, 2017 at 0:19
  • $\begingroup$ I am curious about the motivation of the stated requirement, which somewhat appears strange to me. $\endgroup$ Dec 20, 2017 at 11:09
  • 2
    $\begingroup$ This question first came up when I was using an API. The website suggested I do not abuse the API and limit my entries to once per 10 seconds $\endgroup$ Dec 22, 2017 at 5:23

1 Answer 1

1
$\begingroup$

How about something like

Function[{input}, 
  With[{output = function[input]}, 
   Print[{input, output}];
   Pause[1];
   output
  ]
] /@ {1,2,3}
$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.