[Python-ideas] __len__() for map()

Steven D'Aprano steve at pearwood.info
Sat Dec 1 12:10:18 EST 2018


On Sat, Dec 01, 2018 at 11:27:31AM -0500, David Mertz wrote:
> A proposal to make map() not return an iterator seems like a non-starter.
> Yes, Python 2 worked that way, but that was a long time ago and we know
> better now.

Paul is certainly not suggesting reverting the behaviour to the Python2 
map, at the very least map(func, iterator) will continue to return an 
iterator.

What Paul is *precisely* proposing isn't clear to me, except that 
map(func, sequence) will be "loosely" a sequence. What that means is not 
obvious.

What is especially unclear is what his map() will do when passed 
multiple iterable arguments.


[...]
> list_of_keys can be a concrete list, but I'm using map() mainly
> specifically to get lazy iterator behavior.

Indeed. That's often why I use it too.

But there is a good use-case for having map(), or a map-like function, 
provide either a lazy sequence like range() or a view.

But the devil is in the details. Terry was right to encourage people to 
experiment with their own map-like function (a subclass?) to identify 
any tricky corners in the proposal.


-- 
Steve


More information about the Python-ideas mailing list