On Tue, Nov 30, 2021 at 4:39 AM Christopher Barker <python...@gmail.com> wrote:
>
>
>
> On Mon, Nov 29, 2021 at 2:12 AM Steven D'Aprano <st...@pearwood.info> 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 
> believe the OP was suggesting that they have some methods so that they could 
> be chained.

They cannot be chained using method lookups. One of the proposals is
to have a different form of chaining, which passes the preceding
object as a first parameter.

> There are two tricks here:
>
> 1) What methods to add? There are literally an infinite number of 
> possibilities.
>
> 2) there are multiple ways to create Iterators, how does one make these 
> methods universal?
>

Both can be solved if the construct gets syntactic support rather than
type support. For instance, if this:

1 |> add(2)

is exactly equivalent to this:

add(1, 2)

then neither the iterator nor the consumer needs to be aware of the
new protocol.

I don't like that syntax though, and this will live or die on a good syntax.

ChrisA
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/YUYZWQXUR5KXSSSNXJ4OL777UPDC6WE5/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to