title: How to access items within a collection map without breaking a fluent chain?
body: <p>If you have a simple <code>map</code> using the Laravel collection, you can easily access the base collection by doing the following:</p>
  
  <pre><code>$items = [ "dog", "cat", "unicorn" ];
  collect($items)-&gt;map(function($item) use ($items) {
      d($items); // Correctly outputs $items array
  });
  </code></pre>
  
  <p>If using a fluent chain with filters / rejections, $items no longer represents the set of items:</p>
  
  <pre><code>$items = [ "dog", "cat", "unicorn" ];
  collect($items)
      -&gt;reject(function($item) {
          // Reject cats, because they are most likely evil
          return $item == 'cat'; 
      })-&gt;map(function($item) use ($items) {
          // Incorrectly (and obviously) outputs $items array (including "cat");
          // Would like to see the $items (['dog', 'unicorn']) here
          d($items);
  
          // Will correctly dump 'dog' on iteration 0, and 
          // will correctly dump 'unicorn' on iteration 1 
          d($item); 
      });
  </code></pre>
  
  <p><strong>Question</strong> </p>
  
  <p>Is it possible to access either the modified items array, or alternatively, get access to the collection in its current state. </p>
  
  <p>Similar libraries in Javascript, like lodash, pass in the collection as the third argument - the Laravel collection does not. </p>
  
  <p><strong>Update/Edit</strong></p>
  
  <p>To be clear, I can do something like (but it breaks the chain). I would like to do the following, but without the inbetween storage of the collection. </p>
  
  <pre><code>    $items = [ "dog", "cat", "unicorn" ];
      $items = collect($items)
          -&gt;reject(function($item) {
              // Reject cats, because they are most likely evil
              return $item == 'cat'; 
          });
  
      $items-&gt;map(function($item) use ($items) {
              // This will work (because I have reassigned 
              // the rejected sub collection to $items above)
              d($items);
  
              // Will correctly dump 'dog' on iteration 0, and 
              // will correctly dump 'unicorn' on iteration 1 
             d($item); 
          });
  </code></pre>