title: The best way to break generator into chunks
body: <p>Can you help me to write this code that breaks generator yields into the chunks by 100 and save them into database more beautiful.</p>
  
  <pre><code>$batchSize = 100;
  
  $batch = [];
  $i = 0;
  
  /** 
   * @yield array $item
   */
  foreach(itemsGenerator() as $item) {
      $batch[] = $item;
      $i++;
  
      if ($i === $batchSize) {
          Db::table('items')-&gt;save($batch);
  
          $batch = [];
          $i = 0;
      }
  
      $cnt++;
  }
  
  if ($batch) {
       Db::table('items')-&gt;save($batch);
  }
  </code></pre>
  
  <p>I don't want to put the logic of breaking into chunks in <code>itemsGenerator</code> </p>