Re: Support rewinding of generators

From: Date: Sun, 01 Mar 2020 14:11:27 +0000
Subject: Re: Support rewinding of generators
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-108797@lists.php.net to get a copy of this message
Hi again, Andrea Faulds wrote:
I am not sure if I think this is a good idea… for one thing it may not be necessary to add support in core for this, because you could easily write a userland Iterator class that wraps a generator-returning closure and (re-)invokes it for you. If you do it yourself that way, it's clear what's actually happening behind the scenes at least. If it must be done, perhaps the code must explicitly opt-in to being rewindable somehow? That would avoid problems with rewinding generators which aren't designed for it.
Now that I think about it, such a wrapper class could be part of the PHP standard library. Spl already provides InfiniteIterator and NoRewindIterator, so an InfiniteGenerator class would feel right at home, I think! Thanks, Andrea

« previous php.internals (#108797) next »