Steven D'Aprano <st...@remove-this-cybersource.com.au> writes:
> (4) Expensive generators. The beauty of generators is that they produce 
> values on demand. Making all generators cache their first value means 
> that you pay that cost even if you end up never needing the first value.

You wouldn't generate the cached value ahead of time.  You'd just
remember the last generated value so that you could use it again.
Sort of like getc/ungetc.

An intermediate measure might be to have a stdlib wrapper that added
caching like this to an arbitrary generator.  I've written such things a
few times in various clumsy ways.  Having the caching available in the C
code would eliminate a bunch of indirection.
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to