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