title: Is it possible to access the partial list content while being Sow'ed or must one wait for it to be Reap'ed?
body: <p>I've been learning Sow/Reap. They are cool constructs.  But I need help to see if I can use them to do what I will explain below.</p>
  
  <p>What I'd like to do is:  Plot the solution of <code>NDSolve</code> as it runs. I was thinking I can use <code>Sow[]</code> to collect the solution (x,y[x]) as <code>NDSolve</code> runs using <code>EvaluationMonitor</code>. But I do not want to wait to the end, <code>Reap</code> it and then plot the solution, but wanted to do it as it is running.</p>
  
  <p>I'll show the basic setup example</p>
  
  <pre><code>max = 30;
  sol1 = y /. 
     First@NDSolve[{y'[x] == y[x] Cos[x + y[x]], y[0] == 1}, 
       y, {x, 0, max}];
  Plot[sol1[x], {x, 0, max}, PlotRange -&gt; All, AxesLabel -&gt; {"x", "y[x]"}]
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/2GzMw.png" alt="enter image description here"></p>
  
  <p>Using Reap/Sow, one can collect the data points, and plot the solution at the end like this</p>
  
  <pre><code>sol = Reap[
      First@NDSolve[{y'[x] == y[x] Cos[x + y[x]], y[0] == 1}, 
        y, {x, 0, max}, EvaluationMonitor :&gt; Sow[{x, y[x]}]]][[2, 1]];
  
  ListPlot[sol, AxesLabel -&gt; {"x", "y[x]"}]
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/M5teI.png" alt="enter image description here"></p>
  
  <p>Ok, so far so good. But what I want is to access the partially being build list, as it accumulates by <code>Sow</code> and plot the solution. The only setup I know how do this is to have Dynamic <code>ListPlot</code> that refreshes when its data changes. But I do not know how to use Sow to move the partially build solution to this data so that <code>ListPlot</code> update.</p>
  
  <p>I'll show how I do it without Sow, but you see, I am using <code>AppenedTo[]</code> in the following:</p>
  
  <pre><code>ClearAll[x, y, lst];
  max = 30;
  lst = {{0, 0}};
  Dynamic[ListPlot[lst, Joined -&gt; False, PlotRange -&gt; {{0, max}, All}, 
    AxesLabel -&gt; {"x", "y[x]"}]]
  
  NDSolve[{y'[x] == y[x] Cos[x + y[x]], y[0] == 1}, y, {x, 0, max}, 
   EvaluationMonitor :&gt; {AppendTo[lst, {x, y[x]}]; Pause[0.01]}]
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/rHJ2O.gif" alt="enter image description here"></p>
  
  <p>I was thinking of a way to access the partially build list by Sow and just use that to refresh the plot, on the assumption that might be more efficient than <code>AppendTo[]</code></p>
  
  <p>I can't just do this:</p>
  
  <pre><code>ClearAll[x, y, lst];
  max = 30;
  lst = {{0, 0}};
  Dynamic[ListPlot[lst, Joined -&gt; False, PlotRange -&gt; All]]
  
  NDSolve[{y'[x] == y[x] Cos[x + y[x]], y[0] == 1}, y, {x, 0, max}, 
   EvaluationMonitor :&gt; {lst = Reap[Sow[{x, y[x]}] ][[2, 1]]; Pause[0.01]}]
  </code></pre>
  
  <p>Since it now Sow one point, and Reap it, so I am just plotting one point at a time. The same as if I just did:</p>
  
  <pre><code>NDSolve[{y'[x] == y[x] Cos[x + y[x]], y[0] == 1}, y, {x, 0, max}, 
   EvaluationMonitor :&gt; {lst = Sow[{x, y[x]}]; Pause[0.01]}]
  </code></pre>
  
  <p><strong>my question is, how to use Sow/Reap in the above, to avoid me having manage the lst by the use of AppendTo in this case. (or by pre-allocation using Table, but then I would not know the size to allocate) Since I assume that may be Sow/Reap would be more efficient?</strong></p>
  
  <p>ps. What would be nice, if <code>Reap</code> had an option to tell it to <code>Reap</code> what has been accumulated  by <code>Sow</code>, but do not remove it from what has been Sow'ed so far. Like a passive <code>Reap</code> sort of. Well, just a thought.</p>
  
  <p>thanks</p>
  
  <p><strong>Update: 8:30 am</strong></p>
  
  <p>Thanks for the answers and comments. I just wanted to say, that the main goal of asking this was just to see if there is a way to <em>access</em> part of the data while being Sowed. I need to look more at <code>Bag</code>, I have not used that before.</p>
  
  <p>Btw, The example shown above, was just to give a context to where such a need might appear. If I wanted to simulate the solution in this specific case, I do not even have to do it as I did, I could obtain the solution data first, then, afterwords,  animate it. </p>
  
  <p>Hence no need to even worry about allocation of a buffer myself, or use <code>AppenedTo</code>. But there could many other cases where it will be easier to access the data as it is being accumulated by Sow. This example is just what I had at the moment.</p>
  
  <p>To do this specific example more directly, one can simply used <code>Animate[]</code>, afterwords, like this:</p>
  
  <pre><code>Remove["Global`*"];
  max = 30;
  sol = Reap[
      First@NDSolve[{y'[x] == y[x] Cos[x + y[x]], y[0] == 1}, 
        y, {x, 0, max}, EvaluationMonitor :&gt; Sow[{x, y[x]}]]][[2, 1]];
  
  Animate[ListPlot[sol[[1 ;; idx]], Joined -&gt; False, 
    PlotRange -&gt; {{0, max}, All}, AxesLabel -&gt; {"x", "y[x]"}], {idx, 1, 
    Length[sol], 1}]
  </code></pre>
  
  <p>Or, even make a home grown animate, like this</p>
  
  <pre><code>Remove["Global`*"];
  max = 30;
  sol = Reap[
      First@NDSolve[{y'[x] == y[x] Cos[x + y[x]], y[0] == 1}, 
        y, {x, 0, max}, EvaluationMonitor :&gt; Sow[{x, y[x]}]]][[2, 1]];
  idx = 1;
  Dynamic[idx];
  Dynamic[ListPlot[sol[[1 ;; idx]], Joined -&gt; False, 
    PlotRange -&gt; {{0, max}, All}, AxesLabel -&gt; {"x", "y[x]"}]]
  
  Do[++idx; Pause[0.01], {i, 1, Length[sol] - 1}]
  </code></pre>
  
  <p><strong>Small follow up question:</strong>  Can one depend on using <code>Internal``Bag</code> now? Since it is in <code>Internal</code> context, will there be a chance it might be removed/changed/etc... in the future, breaking some code? I seems to remember reading somewhere that this is not likely, but I do not feel comfortable using something in <code>Internal</code> Context. If it is Ok for us to use it, why is it in Internal context then? </p>
  
  <p>(so many things to lean in Mathematica, so little time)</p>
  
  <p>Thanks,</p>