[Python-ideas] Suggested MapView object (Re: __len__() for map())

Terry Reedy tjreedy at udel.edu
Tue Dec 11 22:36:24 EST 2018

On 12/11/2018 6:50 PM, Greg Ewing wrote:

> I'm not necessarily saying this *should* be done, just pointing
> out that it's a possible strategy for migrating map() from
> an iterator to a view, if we want to do that.

Python has list and list_iterator, tuple and tuple_iterator, set and 
set_iterator, dict and dict_iterator, range and range_iterator.

In 3.0, we could have turned map into a finite sequence analogous to 
range, and add a new map_iterator.  To be completely lazy, such a map 
would have to restrict input to Sequences.  To be compatible with 2.0 
map, it would have to use list(iterable) to turn other finite iterables 
into concrete lists, making it only semi-lazy. Since I am too lazy to 
write the multi-iterable version, here is the one-iterable version to 
show the idea.

     def __init__(func, iterable):
         self.func = func
         self.seq = iterable if isinstance(iterable, Sequence) else 

Given the apparent little need for the extra complication, and the 
possibility of keeping a reference to sequences and explicitly applying 
list otherwise, it was decided to rebind 'map' to the fully lazy and 
general itertools.map.

Terry Jan Reedy

More information about the Python-ideas mailing list