[Python-ideas] Need feedback about exposing an operator overloading in a module

Ethan Furman ethan at stoneleaf.us
Mon Oct 20 22:10:22 CEST 2014


On 10/20/2014 12:42 PM, Julien Palard wrote:
>
> fib() | pp.where(lambda x: x % 2 == 0)
>        | pp.take_while(lambda x: x < 4000000)
>        | pp.add

I find this very readable.


> Pipe(fib()).where(lambda x: x % 2 == 0)
>             .take_while(lambda x: x < 4000000)
>             .add().data

I think this is also readable, although you need to surround the whole thing with parens or end the first two lines with 
'\'.


> It's a bit more dense but still far more readable than the
> classic suffix notation:
>
> pp.add(pp.take_while(lambdax: x < 4000000,
>                       pp.where(lambda x: x % 2 == 0, fib())))

Complete agreement here.  :)


> So a few questions:
>
> 1) Do you think, like me, that exposing a `|` overload is bad ?

I do not see that as a problem, but without using it I can't know for sure.


> 2) In the less intrusive version, do you think, like me, that .register, Pipe(...), and .data are too much ?

I don't see a `.register` in the example, but I don't think Pipe and .data are inappropriate.


> 3) Do you want to see something permitting infix notation in Python
>     standard library ?

No opinion.  Although method chaining isn't strongly supported in the stdlib.

--
~Ethan~


More information about the Python-ideas mailing list