This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Add "compose" function to the functools
Type: enhancement Stage:
Components: Library (Lib) Versions: Python 3.1, Python 2.7
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: amaury.forgeotdarc, collinwinter, eric.araujo, gregory_p, rhettinger, serprex
Priority: normal Keywords:

Created on 2006-06-14 15:12 by gregory_p, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (6)
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) * (Python committer) 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) * (Python committer) 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) * (Python committer) 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) * (Python committer) 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)).
History
Date User Action Args
2022-04-11 14:56:18adminsetgithub: 43496
2010-07-23 23:48:31rhettingersetresolution: works for me -> rejected

messages: + msg111400
nosy: + rhettinger
2010-07-22 14:29:47amaury.forgeotdarcsetstatus: open -> closed
resolution: works for me
2010-07-22 14:28:40amaury.forgeotdarcsetnosy: + amaury.forgeotdarc
messages: + msg111176
2010-07-04 15:15:47eric.araujosetnosy: + eric.araujo
messages: + msg109223
2010-01-07 21:36:21serprexsetnosy: + serprex
messages: + msg97378
2009-03-30 06:32:55ajaksu2setversions: + Python 3.1, Python 2.7, - Python 2.6
2006-06-14 15:12:43gregory_pcreate