This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Unsupported provider

classification
Title: itertools.fixlen
Type: enhancement Stage:
Components: Library (Lib) Versions: Python 3.1, Python 2.7
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: rhettinger Nosy List: lehmannro, pitrou, rhettinger
Priority: normal Keywords: patch

Created on 2009-01-22 18:18 by lehmannro, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
fixlen.patch lehmannro, 2009-01-22 18:18 patch to trunk
Messages (5)
msg80372 - (view) Author: Robert Lehmann (lehmannro) * Date: 2009-01-22 18:18
As raised recently on python-ideas [1]_, an itertools method fixing
iterators to a certain length might be handy (where fixing is either
cutting elements off or appending values).

I appended a patch implementing this feature in Python/C, unit tests and
documentation included.

.. [1] http://thread.gmane.org/gmane.comp.python.ideas/2472/focus=2479
msg80378 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2009-01-22 21:21
"Return an iterator fixing *iterable*\ 's length to *length* by either
cutting elements off or adding *value* to the iterable."

Rather than mixing both, it would be more flexible to have a separate
function for each IMO.
Cutting off is already be handled by islice() (isn't it?), and padding
should be done with a function called e.g. pad() or rpad().
msg80383 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2009-01-22 21:50
Am taking this under advisement but am initially disinclined.  It is not
a basic itertool since it can be composed from the others.  Also, it's
use cases seem to be few.  One challenge for the module is that adding
more tools makes the overall toolkit harder to use because the number of
choices is increased.
msg80418 - (view) Author: Robert Lehmann (lehmannro) * Date: 2009-01-23 15:34
When I started writing this patch this was actually what I intended. But
having ``fixlen(range(3), 2)`` return 0 1 2 struck me as odd. Renaming
the function to `pad` would help there indeed.

It depends on which use case is more common: either fixing an iterator
to a certain length (slicing/padding applied as required) or obtaining
an iterator of *at least* some number of elements (padded as required)?

The thread on python-ideas suggests the latter while the example Python
code brought up there implements the former. OTOH the latter cannot be
composed *that easily* of other itertools but the former is more useful
for unpacking.

On a related note: what should happen if `length` is negative?
`itertools.repeat` just defaults to 0 in such cases but I am unsure how
applicable that is in this case.
msg80483 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2009-01-24 21:42
Am still leaning towards rejecting this one based on:
* paucity of use cases
* non-atomicity (it can be built-out of existing tools)
* minimizing the number of tools in the toolkit
* not convinced that padded tuple unpacking is desirable
History
Date User Action Args
2022-04-11 14:56:44adminsetgithub: 49284
2009-01-27 05:15:45rhettingersetstatus: open -> closed
resolution: rejected
2009-01-24 21:42:04rhettingersetmessages: + msg80483
2009-01-23 15:34:06lehmannrosetmessages: + msg80418
2009-01-22 21:50:52rhettingersetmessages: + msg80383
2009-01-22 21:21:40pitrousetnosy: + pitrou
messages: + msg80378
2009-01-22 18:44:38rhettingersetassignee: rhettinger
nosy: + rhettinger
versions: + Python 3.1
2009-01-22 18:18:41lehmannrocreate