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
list(iterable)
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
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/