[Python-ideas] add fluent operator to everything
Steven D'Aprano
steve at pearwood.info
Wed Feb 20 10:10:29 EST 2019
On Tue, Feb 19, 2019 at 01:52:34PM -0800, Brett Cannon wrote:
> On Tue, Feb 19, 2019 at 6:23 AM Jimmy Girardet <ijkl at netc.fr> wrote:
[...]
> > 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.
> >
>
> Easy for you, but not necessarily everyone else. For instance, I find the
> explicit writing out of the lines easier.
That's possibly a matter of familiarity. I'd be very surprised if you
preferred this:
mystr = mystr.strip()
mystr = mystr.expandtabs()
mystr = mystr.lower()
mystr = mystr.replace('ham', 'spam')
result = function(mystr)
over this fluent version:
result = function(mystr.strip().expandtabs().lower().replace('ham', 'spam'))
Or if you're worried about the line length:
result = function(mystr.strip()
.expandtabs()
.lower()
.replace('ham', 'spam')
)
works for me.
--
Steven
More information about the Python-ideas
mailing list