If I may chime in, not all iterators support rewind, at least not as outlined.

There exists also the NoRewindIterator which you can just use to decorate an 
iterator out of a generator to not make it do a fatal.

However as far as a generator is concerned, it probably should just behave like 
NoRewindIterator already so not give any errors on rewind. Because you can not 
rewind what you can not rewind. No need to error, no need to do something. The 
function is just there because of the interface, but it must not do anything.

If different behavior is needed it could be decorated, but right now I can not 
imagine why rewind would be called (apart from using in foreach() for the first 
time which implies a rewind and that one is already like I suggest.)


My 2 cents.

-- hakre



----- Ursprüngliche Message -----
> Von: Nikita Popov <nikita....@gmail.com>
> An: Brian Moon <br...@moonspot.net>
> CC: PHP internals <internals@lists.php.net>
> Gesendet: 18:09 Montag, 13.August 2012
> Betreff: Re: [PHP-DEV] [RFC] Generators
> 
> On Sun, Aug 12, 2012 at 10:08 PM, Brian Moon <br...@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
> 
> -- 
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to