sequence = $sequence; $this->count = count($sequence); } /** * Get the current count of the sequence items. * * @return int */ public function count(): int { return $this->count; } /** * Get the next value in the sequence. * * @return mixed */ public function __invoke() { return tap(value($this->sequence[$this->index % $this->count], $this), function () { $this->index = $this->index + 1; }); } }