Re: [RFC] Generators
| From: | Alex Aulbach | Date: | Tue, 14 Aug 2012 12:37:48 +0000 |
| Subject: | Re: [RFC] Generators | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-62142@lists.php.net to get a copy of this message | ||
2012/8/13 Nikita Popov <nikita.ppv@gmail.com>:
> * 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.
Hm. I think this looks like a workaround over conceptual problems.
The (in my eyes) "right" behavior would be to call a new instance of
the generator if you rewind and destroy the current (= replace current
generator with a new).
I would prefer to say "this is not an real iterator"; if you want to
make it an real iterator, then implement it yourself.
Otherwise it's like "Ok, we have here a new type of function which
looks enough like a function to be a function, which implements an
iterator which looks enough like an iterator to be an iterator.". :)
I also recommend to say, that generators aren't a good idea if used on
resources, which can't be shared. For example: the file-read-example
doesn't lock. To implement locking new functions or a new class is
needed - hiding complexity.
Generators are (in my opinion) really nice for things which are
already in the memory. Not more or less.
--
Alex Aulbach