Re: [RFC] Generators
| From: | Nikita Popov | Date: | Mon, 13 Aug 2012 16:09:32 +0000 |
| Subject: | Re: [RFC] Generators | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-62129@lists.php.net to get a copy of this message | ||
On Sun, Aug 12, 2012 at 10:08 PM, Brian Moon <brian@moonspot.net> wrote:
> Also, not allowing rewinding is unintuitive for something that is an
> iterator in PHP. If I can foreach() it and I can call next() on it, I expect
> to be able to reset() it as well. IMO, you would need to issue a FATAL PHP
> error if that simply is not allowed. Or you have to have a second syntax for
> what to do in that case. At that point, you are implementing Iterator.
Currently I'm planning to implement the following behavior for rewind():
* If before first yield: Resume to first yield (this priming behavior
is common to all the Iterator methods)
* At first yield: No-op
* After first yield: Recoverable fatal error
So this would allow you to call ->rewind() after creating the
generator, but will throw an error if you try to do so later.
Another thing that I'd like to do is drop the ->close() method. It
doesn't really make sense to explicitly close generators.
Any objects to those two things?
Nikita