[Python-ideas] Function composition (was no subject)
Steven D'Aprano
steve at pearwood.info
Sun May 10 11:31:25 CEST 2015
On Sat, May 09, 2015 at 01:30:17PM -0500, David Mertz wrote:
> On Sat, May 9, 2015 at 1:16 PM, Steven D'Aprano <steve at pearwood.info> wrote:
>
> > On Sat, May 09, 2015 at 11:38:38AM -0400, Ron Adam wrote:
> >
> > > How about an operator for partial?
> > >
> > > root @ mean @ map $ square(xs)
> >
>
> I have trouble seeing the advantage of a special function composition
> operator when it is easy to write a general 'compose()' function that can
> produce such things easily enough.
Do you have trouble seeing the advantage of a special value addition
operator when it is easy enough to write a general "add()" function?
*wink*
I think that, mentally, operators "feel" lightweight. If I write:
getattr(obj, 'method')(arg)
it puts too much emphasis on the attribute access. But using an
operator:
obj.method(arg)
put the emphasis on calling the method, not looking it up, which is just
right. Even though both forms do about the same about of work, mentally,
the dot pseudo-operator feels much more lightweight.
The same with
compose(grep, filter)(data)
versus
(grep @ filter)(data)
The first sends my attention to the wrong place, the composition. The
second does not.
I don't expect everyone to agree with me, but I think this explains why
people keep suggesting syntax or an operator to do function composition
instead of a function. Not everyone thinks this way, but for those who
do, a compose() function is like eating a great big bowl gruel that
contains all the nutrients you need for the day and tastes of cardboard
and smells of wet dog. It might do everything that you want
functionally, but it feels wrong and looks wrong and it is not in the
least bit pleasurable to use.
--
Steve
More information about the Python-ideas
mailing list