An "adapter", superset of an iterator

Greg Ewing greg.ewing at canterbury.ac.nz
Wed May 3 20:01:01 EDT 2023


On 4/05/23 9:29 am, Chris Angelico wrote:
> So
> you're asking for map to be able to return an iterator if given an
> iterator, or an adapter if given an adapter. That makes it quite
> complicated to use and reason about.

Also a bit slower, since it would need to inspect its argument
and decide what to do with it. Currently it can just get on
with its job and rely on duck typing to do the right thing.

Maybe there could be a parallel set of functions "enumerated",
"mapped", etc. that take sequences and return sequence views.

Although that naming convention would suggest that reversed()
itself should return a sequence view rather than an iterator.
That would require restricting it to working on sequences,
which would be an incompatible change.

-- 
Greg


More information about the Python-list mailing list