[Python-ideas] add fluent operator to everything

Chris Angelico rosuav at gmail.com
Tue Feb 19 09:54:44 EST 2019


On Wed, Feb 20, 2019 at 1:22 AM Jimmy Girardet <ijkl at netc.fr> wrote:
> >>> a = [1,2,3]
> >>> a.append(4)
> >>> a.sort()
> >>> c = max(a) + 1
>
> I would be happy to have
> >>> [1,2,3].append(4)::sort()::max() +1
>
> It makes things very easy to read: first create list, then append 4,
> then sort, then get the max.
>
> To resume, the idea is to apply via a new operator (::, .., etc...) the
> following callable on the previous object. It's clearly  for standalone
> object or after a method call when the return is None (there is fluent
> `.` when there is a return value)

Hmm. The trouble is, there's no consistent "previous object" for each
of your steps. You're mixing together "max()" which is a built-in, and
"sort()" which is a method. Your proposed semantics (which I snipped)
will happily cover built-ins, but not methods.

Proposals broadly similar to these (but generally, if my memory
serves, focusing on methods only) have come up periodically. You may
want to briefly search the mailing list archives to find discussions
on "method chaining".

ChrisA


More information about the Python-ideas mailing list