<?php
namespace Symfony\Component\DependencyInjection\Argument;
class RewindableGenerator implements \IteratorAggregate, \Countable
{
private \Closure $generator;
private \Closure|int $count;
public function __construct(callable $generator, int|callable $count)
{
$this->generator = $generator(...);
$this->count = \is_int($count) ? $count : $count(...);
}
public function getIterator(): \Traversable
{
$g = $this->generator;
return $g();
}
public function count(): int
{
if (!\is_int($count = $this->count)) {
$this->count = $count();
}
return $this->count;
}
}