[Python-ideas] Re: Enhancing iterator objects with map, filter, reduce methods

2021-11-29 Thread Chris Angelico
On Tue, Nov 30, 2021 at 4:39 AM Christopher Barker wrote: > > > > On Mon, Nov 29, 2021 at 2:12 AM Steven D'Aprano wrote: > >> Since most iterators don't have many methods, it's not clear to me that >> iterators are even a little bit relevant. > > > I think you just answered your own question. >

[Python-ideas] Re: Enhancing iterator objects with map, filter, reduce methods

2021-11-29 Thread Christopher Barker
On Mon, Nov 29, 2021 at 2:12 AM Steven D'Aprano wrote: Since most iterators don't have many methods, it's not clear to me that > iterators are even a little bit relevant. I think you just answered your own question. Since iterators in general don’t have methods, they can not be chained. I

[Python-ideas] Magnitude and ProtoMagnitude ABCs — primarily for argument validation

2021-11-29 Thread kana70416
Andrew Barnert via Python-ideas writes: ... Is there any commonly used or even imaginable useful type that uses them in weirder ways than set and float (which are both partially ordered) or np? array (where they aren’t even Boolean-values)? I've had occasion (a class for outcomes in two-player

[Python-ideas] Re: Enhancing iterator objects with map, filter, reduce methods

2021-11-29 Thread Steven D'Aprano
On Mon, Nov 29, 2021 at 08:44:00AM -0500, David Mertz, Ph.D. wrote: > On Mon, Nov 29, 2021 at 5:15 AM Steven D'Aprano wrote: > > > - the method modifies the object in place, and returns self; > > - versus the method returns a new, modified, copy of the object. > > Pandas uses the first style (I

[Python-ideas] Re: Enhancing iterator objects with map, filter, reduce methods

2021-11-29 Thread David Mertz, Ph.D.
On Mon, Nov 29, 2021 at 5:15 AM Steven D'Aprano wrote: > - the method modifies the object in place, and returns self; > - versus the method returns a new, modified, copy of the object. > Pandas uses the first style (I think; corrections welcome). Strings use > the second, because they have no

[Python-ideas] Re: Enhancing iterator objects with map, filter, reduce methods

2021-11-29 Thread Stephen J. Turnbull
Steven D'Aprano writes: > And yet it is indisputable that chained methods are useful even for > methods which modify the object they work on. Look at pandas: Guido disputed that it was useful *enough*. My point was advice to the proponent to get his proposal adopted (despite the fact that I

[Python-ideas] Re: Enhancing iterator objects with map, filter, reduce methods

2021-11-29 Thread Raimi bin Karim
Steven D'Aprano wrote: > Does anyone know what builtin or stdlib objects iterators fail to > implement `__iter__`? I haven't been able to find any -- all the obvious > examples do (map, filter, reversed, zip, generators, list iterators, > set iterators, etc). Could it possibly be... the async

[Python-ideas] Re: Enhancing iterator objects with map, filter, reduce methods

2021-11-29 Thread Steven D'Aprano
On Sat, Nov 27, 2021 at 08:50:37PM +0900, Stephen J. Turnbull wrote: > The thing is, the reason such a module is needed at all is that Guido > decided ages ago that mutating methods should return None, and in > particular they don't return self. > > I'm not sure why he did that, you'd have to

[Python-ideas] Re: Enhancing iterator objects with map, filter, reduce methods

2021-11-29 Thread Steven D'Aprano
On Sun, Nov 28, 2021 at 05:28:58PM +, Evpok Padding wrote: > Hi, > > All apologies if it has been clarified earlier, but if you dislike nested > method calls what is wrong with operating on generators as in > > ```pycon > >>> itr = (i**2 for i in range(8)) > >>> itr = (i-1 for i in itr if i

[Python-ideas] Re: Enhancing iterator objects with map, filter, reduce methods

2021-11-29 Thread Steven D'Aprano
On Sun, Nov 28, 2021 at 10:35:34PM -0800, Christopher Barker wrote: > Of course, Python being Python, if in a given use case, you don’t need > __iter__, you don’t have to have it. [cynicism=on] If you think your iterator doesn't need `__iter__`, just wait, and you will find that it does.

[Python-ideas] Re: Enhancing iterator objects with map, filter, reduce methods

2021-11-29 Thread Steven D'Aprano
On Sun, Nov 28, 2021 at 09:33:17PM -0800, Paul Bryan wrote: > 1. Noted: Python's for statement will happily iterate over an object > that only implements __next__. That is not correct. >>> class C(object): ... def __next__(self): ... return 1 ... >>> for i in C(): ...

[Python-ideas] Re: Enhancing iterator objects with map, filter, reduce methods

2021-11-29 Thread Steven D'Aprano
On Mon, Nov 29, 2021 at 12:11:43AM -0500, David Mertz, Ph.D. wrote: > On Sun, Nov 28, 2021, 11:43 PM Paul Bryan wrote: > > > According to https://docs.python.org/3/glossary.html#term-iterator and > > https://docs.python.org/3/library/stdtypes.html#typeiter, iterators must > > implement the