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

2018-12-11 Thread Steven D'Aprano
On Tue, Dec 11, 2018 at 12:48:10PM +0100, E. Madison Bray wrote: > Right now I'm specifically responding to the sub-thread that Greg > started "Suggested MapView object", so I'm considering this a mostly > clean slate from the previous thread "__len__() for map()". Different > ideas have been

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

2018-12-11 Thread Steven D'Aprano
On Mon, Dec 10, 2018 at 05:15:36PM -0800, Chris Barker via Python-ideas wrote: [...] > I'm still confused -- what's so wrong with: > > list(map(func, some_iterable)) > > if you need a sequence? You might need a sequence. Why do you think that has to be an *eager* sequence? I can think of two

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

2018-12-11 Thread Chris Barker - NOAA Federal via Python-ideas
Perhaps I got confused by the early part of this discussion. My point was that there is no “map-like” object at the Python level. (That is no Map abc). Py2’s map produced a sequence. Py3’s map produced an iterable. So any API that was expecting a sequence could accept the result of a py2 map,

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

2018-12-11 Thread Chris Barker via Python-ideas
On Tue, Dec 11, 2018 at 11:10 AM Terry Reedy wrote: > > I _think_ someone may be advocating that map() could return an > > iterable if it is passed a iterable, > > I believe you mean 'iterator' rather than 'iterable' here and below as a > sequence is an iterable. > well, the iterator / iterable

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

2018-12-11 Thread Greg Ewing
Steven D'Aprano wrote: The iterator protocol is that iterators must: - have a __next__ method; - have an __iter__ method which returns self; and the test for an iterator is: obj is iter(obj) By that test, it identifies as a sequence, as does testing it for the presence of __len__: >>>

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

2018-12-11 Thread Greg Ewing
Steven D'Aprano wrote: I suggest we provide a separate mapview() type that offers only the lazy sequence API, without trying to be an iterator at the same time. Then we would be back to the bad old days of having two functions that do almost exactly the same thing. My suggestion was made in

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

2018-12-11 Thread Steven D'Aprano
On Wed, Dec 12, 2018 at 11:31:03AM +1300, Greg Ewing wrote: > Steven D'Aprano wrote: > >I suggest we provide a separate mapview() type that offers only the lazy > >sequence API, without trying to be an iterator at the same time. > > Then we would be back to the bad old days of having two

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

2018-12-11 Thread Terry Reedy
On 12/11/2018 12:01 PM, Chris Barker - NOAA Federal via Python-ideas wrote: Perhaps I got confused by the early part of this discussion. My point was that there is no “map-like” object at the Python level. (That is no Map abc). Py2’s map produced a sequence. Py3’s map produced an iterable. So

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

2018-12-11 Thread Terry Reedy
On 12/1/2018 2:08 PM, Steven D'Aprano wrote: This proof of concept wrapper class could have been written any time since Python 1.5 or earlier: class lazymap: def __init__(self, function, sequence): One could now add at the top of the file from collections.abc import Sequence and

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

2018-12-11 Thread Terry Reedy
On 12/11/2018 6:48 AM, E. Madison Bray wrote: The idea would be to now enhance the existing built-ins to restore at least some previously lost assumptions, at least in the relevant cases. To give an analogy, Python 3.0 replaced range() with (effectively) xrange(). This broken a lot of

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

2018-12-11 Thread Terry Reedy
On 12/1/2018 8:07 PM, Greg Ewing wrote: Steven D'Aprano wrote: After defining a separate iterable mapview sequence class For backwards compatibilty reasons, we can't just make map() work like this, because that's a change in behaviour. Actually, I think it's possible to get the best of

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

2018-12-11 Thread Terry Reedy
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,

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

2018-12-11 Thread E. Madison Bray
On Tue, Dec 11, 2018 at 2:16 AM Chris Barker wrote: > On Mon, Dec 10, 2018 at 5:23 AM E. Madison Bray wrote: >> >> Indeed; I believe it is very useful to have a map-like object that is >> effectively an augmented list/sequence. > > > but what IS a "map-like object" -- I'm trying to imagine what

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

2018-12-11 Thread E. Madison Bray
On Tue, Dec 11, 2018 at 12:13 PM Paul Moore wrote: > > On Tue, 11 Dec 2018 at 10:38, E. Madison Bray wrote: > > I don't understand why this is confusing. > [...] > > For something like a fixed sequence a "map" could just as easily be > > defined as a pair (, ) that applies , > > which I'm

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

2018-12-11 Thread Paul Moore
On Tue, 11 Dec 2018 at 11:49, E. Madison Bray wrote: > The idea would be to now enhance the existing built-ins to restore at > least some previously lost assumptions, at least in the relevant > cases. To give an analogy, Python 3.0 replaced range() with > (effectively) xrange(). This broken a

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

2018-12-11 Thread Paul Moore
On Tue, 11 Dec 2018 at 10:38, E. Madison Bray wrote: > I don't understand why this is confusing. [...] > For something like a fixed sequence a "map" could just as easily be > defined as a pair (, ) that applies , > which I'm claiming is a pure function, to every element returned by > the . This