I'm not confident I can make that case very well, but I suppose I can try :). There do seem to be some hand-rolled composition functions in various Github repositories: https://github.com/search?l=python&q=%22def+compose%22&ref=searchresults&type=Code I'm not sure why a composition operator has never been added to the functools library, but I'd make the observation that a composition function wouldn't be much less verbose than in my earlier lambda example. A infix binary operator, however, would be quite more concise, especially so when chaining multiple functions. There's also precedent to the @ symbol being associated with functions, i.e. decorator syntax. Decorators are callables that accept callables and return callables, which parallels the infix definition of accepting two callables and returning a callable. On Tue, Apr 8, 2014 at 2:17 PM, Nathaniel Smith <njs@pobox.com> wrote:
It's been raised a few times, but the problem is that there's no evidence that anyone actually needs a short way to perform composition - notice the composition operation's never even been added to functools. If you do want to make that case though then there's nothing stopping you :-) On 8 Apr 2014 22:10, "Michael Mitchell" <epsilonmichael@gmail.com> wrote:
I haven't been following this thread too closely, so please stop me if this has been covered, but has overloading the @ operator as function composition been considered yet?
An example would be
filter(a @ b, lst)
as opposed to
filter(lambda x: a(b(x)), lst)
On Sun, Apr 6, 2014 at 6:51 PM, Nathaniel Smith <njs@pobox.com> wrote:
On Mon, Apr 7, 2014 at 12:20 AM, Steven D'Aprano <steve@pearwood.info> wrote:
On Sun, Apr 06, 2014 at 11:02:00PM +0100, Nathaniel Smith wrote:
On Sun, Mar 16, 2014 at 1:05 PM, Nick Coghlan <ncoghlan@gmail.com> wrote:
Aye, but at the moment it makes sense to wait and see if there is even an argument to be had - Nathaniel may decide that even after reviewing the question seriously, he doesn't want to propose a right associative operator :)
And indeed, that does seem to be the way things have worked out :-).
http://mail.scipy.org/pipermail/numpy-discussion/2014-April/069834.html
That's a shame in one way -- for anyone using operator overloading to define their own DSL, there's only ** if you want a right-associative operator to overload. Still, that's an extremely marginal, and hypothetical, use-case. Left-associative it is.
Was that the last blocker for the PEP?
Pretty much. Just posted to python-dev: https://mail.python.org/pipermail/python-dev/2014-April/133791.html
-n
-- Nathaniel J. Smith Postdoctoral researcher - Informatics - University of Edinburgh http://vorpus.org _______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/