[Python-ideas] Where should grouping() live
greg.ewing at canterbury.ac.nz
Tue Jul 3 18:35:04 EDT 2018
David Mertz wrote:
> make grouping() a generator function rather than a plain function. This
> lets us get an incremental grouping of an iterable. This can be useful
> if the iterable is slow or infinite, but the partial groupings are
> useful in themselves.
Do you have any real-world examples? I'm having trouble
thinking of any.
Even if there are a few, it seems like the vast majority of
the time you *won't* want the intermediate groupings, just
the final one, and then what do you do? It would be annoying
to have to write code to exhaust the iterator just to get the
result you're after.
Also, were you intending it to return a series of independent
objects, or does it just return the same object every time,
adding stuff to it? The former would be very inefficient for
the majority of uses, whereas the latter doesn't seem to
be in keeping with the spirit of itertools.
This idea seems like purity beating practicality to me.
More information about the Python-ideas