Iterator class to allow self-restarting generator expressions?

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Mon Mar 2 06:43:31 EST 2009


En Mon, 02 Mar 2009 06:48:02 -0200, Lie Ryan <lie.1296 at gmail.com> escribió:
> Gabriel Genellina wrote:
>> En Sun, 01 Mar 2009 15:51:07 -0200, Chris Rebert <clp2 at rebertia.com>
>> escribió:
>>> On Sun, Mar 1, 2009 at 8:54 AM, Gabriel Genellina
>>> <gagsl-py2 at yahoo.com.ar> wrote:
>>>> En Sun, 01 Mar 2009 13:20:28 -0200, John O'Hagan
>>>> <research at johnohagan.com>
>>>> escribió:
>>>>
>>>>> Inspired by some recent threads here about using classes to extend  
>>>>> the
>>>>> behaviour of iterators, I'm trying to replace some some top-level
>>>>> functions
>>>>> aimed at doing such things with a class.
>>
>>>> I'm afraid you can't do that. There is no way of "cloning" a  
>>>> generator:
>>>
>>> Really? What about itertools.tee()? Sounds like it'd do the job,
>>> albeit with some caveats.
>>> http://docs.python.org/library/itertools.html#itertools.tee
>>
>> It doesn't clone the generator, it just stores the generated objects in
>> a temporary array to be re-yielded later.
>
> How about creating something like itertools.tee() that will save and
> dump items as necessary. The "new tee" (let's call it tea) would return
> several generators that all will refer to a common "tea" object. The
> common tea object will keep track of which items has been collected by
> each generators and generate new items as necessary. If an item has
> already been collected by all generators, that item will be dumped.

That's exactly what itertools.tee does! Or I'm missing something?

-- 
Gabriel Genellina




More information about the Python-list mailing list