[Python-ideas] Method chaining notation

Westley Martínez anikom15 at gmail.com
Sun Feb 23 21:24:58 CET 2014


On Feb 23, 2014 10:25 AM, "Ron Adam" <ron3200 at gmail.com> wrote:
> I agree with nick, this looks like a transformation chain. Each step
transforming the "new" result of the previous step.
>
>
>       seq = []->extend(get_data())->sort()
>
>
>
> To make it pythonic ...
>
>
> The operator you want is one for an in place method call. If we apply the
"+=" pattern for the '__iadd__' method call syntax, to the more the general
'.' method syntax, we get ".=", the in place method call syntax.
>
>    seq = []
>    seq .= extend(get_data())    # In place method call.
>
> In place method calls seem quite reasonable to me.
>
>
>
> And then to get the rest of the way there, allow chained "in place"
method calls.
>
>    seq = [] .= extend(get_data()) .= sort()
>
> Which should be a separate pep from the ".=" enhancement.
>
>
>
> BTW... allowing ".=" could mean a class could have one __iget_method__
attribute instead of multiple __ixxxx___ methods. (Or something like that.)
>
> Cheers,
>     Ron

I like this syntax. It easy to tell what exactly is getting mutated.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140223/20e18478/attachment.html>


More information about the Python-ideas mailing list