On Wed, Nov 28, 2018 at 11:27 PM Steven D'Aprano <st...@pearwood.info> wrote: > > On Wed, Nov 28, 2018 at 02:53:50PM -0500, Terry Reedy wrote: > > What makes the map class special among all built-in iterator classes? > > It appears not to be a property of the class itself, as an iterator > > class, but of its name. In Python 2, 'map' was bound to a different > > implementation of the map idea, a function that produced a list, which > > has a length. I suspect that if Python 3 were the original Python, we > > would not have this discussion. > > No, in fairness, I too have often wanted to know the length of an > arbitrary iterator, including map(), without consuming it. In general > this is an unsolvable problem, but sometimes it is (or at least, at first > glance *seems*) solvable. map() is one of those cases. > > If we could solve it, that would be great -- but I'm not convinced that > it is solvable, since the solution seems worse than the problem it aims > to solve. But I live in hope that somebody cleverer than me can point > out the flaws in my argument.
In general it's unsolvable, so no attempt should be made to provide a pre-baked attempt at a solution that won't always work. But in many, if not the majority of cases, it *is* solvable. So let's give intelligent people the tools they need to solve it in those cases that they know they can solve it :) > But that wouldn't have helped E. Madison Bray or SageMath, since their > difficulty is not their own internal use of map(), but their users' use > of map(). > > Unless they simply ban any use of iterators at all, which I imagine will > be a backwards-incompatible change (and for that matter an excessive > overreaction for many uses), SageMath can't prevent users from providing > map() objects or other iterator arguments. That is the majority of the case I was concerned about, yes. _______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/