msg54820 - (view) |
Author: Gregory Petrosyan (gregory_p) |
Date: 2006-06-14 15:12 |
I think it would be very usefull to have something similar to Haskell's "dot" operator in Python, IMO it should be something like this (untested): def compose(f, g): return lambda *args, **kws: f(g(*args, **kws)) but C-coded. So, _functools can be a good place for it. -- Regards, Gregory. |
|
|
msg54821 - (view) |
Author: Collin Winter (collinwinter) *  |
Date: 2007-03-19 19:07 |
If there's interest in this, I already have an implementation in my functional package (http://cheeseshop.python.org/pypi/functional). |
|
|
msg97378 - (view) |
Author: Demur Rumed (serprex) |
Date: 2010-01-07 21:36 |
A type safe compose could be useful. One which instead of returning a function that takes (*args,**kwargs), takes the same as the first function which the arguments would be passed to. Copying a functions argument semantics would be useful in general, such as for decorators |
|
|
msg109223 - (view) |
Author: Éric Araujo (eric.araujo) *  |
Date: 2010-07-04 15:15 |
Gregory, any update on this? Maybe you can poll python-ideas. Collin, any download stats and feedback on your package? |
|
|
msg111176 - (view) |
Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) *  |
Date: 2010-07-22 14:28 |
The proposed code may be useful sometimes, but is not generic enough for the standard library. For example, the f() function can only take one argument, when g() can accept any number. Implementations of this kind are so easy to write, They are better described by their implementation rather than documentation. IMO they show the expressiveness of python, and don't need to be hidden in a C module. |
|
|
msg111400 - (view) |
Author: Raymond Hettinger (rhettinger) *  |
Date: 2010-07-23 23:48 |
I agree with Amaury that this should be closed. It has been previously discussed and rejected in other forums. One the issues is that the usual mathematical order is unintuitive and not self-documenting -- i.e. is compose(f,g) the same as f(g(x)) or g(f(x))? Also, it is already dirt simple to create your own compose function or to do the composition directly: h = lambda x: f(g(x)). |
|
|