Updated code.
I could not find how to edit a note :/
Preventing segfault if empty generator.
<?php
$append_iterator = new \AppendIterator();
$generator = some_generator();
// Only works if first value in generator is not empty
// useful when yielding arrays
foreach ($generator as $value)
{
//If first $value not empty, generator is not empty.
if(!empty($value))
{
$append_iterator->append($generator );
//break out of loop after appending.
break;
}
}