original_string: protected static function recordset_loop_and_export(moodle_recordset $recordset, $splitkey, $initial,
              callable $reducer, callable $export) {
  
          $data = $initial;
          $lastid = null;
  
          foreach ($recordset as $record) {
              if ($lastid && $record->{$splitkey} != $lastid) {
                  $export($lastid, $data);
                  $data = $initial;
              }
              $data = $reducer($data, $record);
              $lastid = $record->{$splitkey};
          }
          $recordset->close();
  
          if (!empty($lastid)) {
              $export($lastid, $data);
          }
      }
code: protected static function recordset_loop_and_export(moodle_recordset $recordset, $splitkey, $initial,
              callable $reducer, callable $export) {
  
          $data = $initial;
          $lastid = null;
  
          foreach ($recordset as $record) {
              if ($lastid && $record->{$splitkey} != $lastid) {
                  $export($lastid, $data);
                  $data = $initial;
              }
              $data = $reducer($data, $record);
              $lastid = $record->{$splitkey};
          }
          $recordset->close();
  
          if (!empty($lastid)) {
              $export($lastid, $data);
          }
      }
code_tokens: protected static function recordset_loop_and_export ( moodle_recordset $ recordset , $ splitkey , $ initial , callable $ reducer , callable $ export ) { $ data = $ initial ; $ lastid = null ; foreach ( $ recordset as $ record ) { if ( $ lastid && $ record -> { $ splitkey } != $ lastid ) { $ export ( $ lastid , $ data ) ; $ data = $ initial ; } $ data = $ reducer ( $ data , $ record ) ; $ lastid = $ record -> { $ splitkey } ; } $ recordset -> close ( ) ; if ( ! empty ( $ lastid ) ) { $ export ( $ lastid , $ data ) ; } }
docstring: Loop and export from a recordset.
  
  @param moodle_recordset $recordset The recordset.
  @param string $splitkey The record key to determine when to export.
  @param mixed $initial The initial data to reduce from.
  @param callable $reducer The function to return the dataset, receives current dataset, and the current record.
  @param callable $export The function to export the dataset, receives the last value from $splitkey and the dataset.
  @return void
docstring_tokens: Loop and export from a recordset .