public function aggregate(callable $func, $seed = null)
{
$result = null;
$first = true;
if ($seed !== null) {
$result = $seed;
$first = false;
}
foreach ($this->iterator as $current) {
if (!$first) {
$result = $func($result, $current);
} else {
$result = $current;
$first = false;
}
}
if ($first) {
throw new \RuntimeException("The input sequence contains no elements.");
}
return $result;
}