[Python-Dev] functools.compose to chain functions together
Jason R. Coombs
jaraco at jaraco.com
Sun Aug 16 19:15:21 CEST 2009
> Raymond Hettinger wrote:
> Sent: Sunday, 16 August, 2009 12:42
>
> [Antoine Pitrou]
> > I also think it would be a nice addition.
> > (but someone has to propose a patch :-))
The patch was proposed and rejected here: http://bugs.python.org/issue1660179; my reason for mentioning it here is because the functionality isn't YAGNI for me; It seems like a fundamental capability when employing a functional programming paradigm.
> I agree with Martin's reasons for rejecting the feature request
> (see the bug report for his full explanation). IIRC, the compose()
> idea had come-up and been rejected in previous discussions as well.
>
> At best, it will be a little syntactic sugar (though somewhat odd
> because
> the traditional mathematical ordering of a composition operator is the
> opposite of what intuition would suggest). At worst, it will be slower
> and less flexible than our normal ways of linking functions together.
>
> IMO, its only virtue is that people coming from functional languages
> are used to having compose. Otherwise, it's a YAGNI.
Right. I have great respect for your and Martin's original conclusion.
The reason I came across the old patch was because I was searching for something that did exactly what compose does. That is to say, I had a use case that was compelling enough that I thought there should be something in functools to do what I wanted. I've encountered this pattern often enough that it might be in the stdlib.
As it turns out, it isn't. For this reason, I wanted to voice my opinion that contradicts the conclusion of the previous patch discussion. Specifically, YAGNI doesn't apply to my experiences, and it does seem to have broad, fundamental application, especially with respect to functional programming.
I'm not arguing that just because Jason needs it, it should be in the standard library. Rather, I just wanted to express that, like Chris AtLee, I would find this function quite useful.
As Steven pointed out, this functionality is desirable even for those without a functional programming background. I'd like to mention also that even though I learned to program in Scheme in 1994, I haven't used it since, and I've been using Python since 1996, so my affinity for this function is based almost entirely from experiences programming in Python and not in a primarily functional language.
If the Python community still concurs that 'compose' is YAGNI or otherwise undesirable, I understand. I just wanted to share my experiences and motivations as they pertain to the discussion. If it turns out that it's included in the stdlib later, all the better.
Respectfully,
Jason
More information about the Python-Dev
mailing list