[Python-ideas] Batching/grouping function for itertools
Ron Adam
ron3200 at gmail.com
Sun Dec 8 17:07:07 CET 2013
On 12/08/2013 09:46 AM, Chris Angelico wrote:
> On Mon, Dec 9, 2013 at 2:40 AM, Ron Adam<ron3200 at gmail.com> wrote:
>> >The function would need to be a wrapper that keeps a buffer. And the front
>> >of the buffer would always be the next to be yielded if there is anything in
>> >it.
> Which is what Stephen said in his pithy message above. Yes, it's
> theoretically possible, but it's not something to do in the general
> case. Not something to depend on for a chunker/grouper, which should
> be able to pass once over the underlying iterator.
For the windowed chunker that was being discussed and uses that are
similar, they need to hold references to some yielded items some place.
This just packages that need in a convenient way.
It almost seems to me that coroutines, which is the counter example you
suggested, should maybe be a type of their own. That way, they can be
tested. (And raise an error if used in cases like this.)
But that's whole other topic. Best answer for now is don't do that.
Cheers,
Ron
More information about the Python-ideas
mailing list