In many cases, especially for streaming sources, Generators are way more efficient. I noticed that the AppendIterator buffers the entire "inner iterator".
<?php
function append_iterators(...$iterators){
foreach($iterators as $iterator)
foreach($iterator as $row)
yield($row);
}
function merge_iterators(....$its) {
$numberOfIts = sizeof($its);
while($numberOfIts > 0) {
$iterator = array_shift($its);
yield($iterator->current());
$iterator->next();
if($iterator->valid())
$its[] = $iterator;
else
$numberOfIts--;
}
});
?>