generator = $generator; $this->count = $count; } public function getIterator() : \Traversable { $g = $this->generator; return $g(); } public function count() : int { if (\is_callable($count = $this->count)) { $this->count = $count(); } return $this->count; } }