Some time ago I looked over Haskell docs and found it\'s functional composition operator really nice. So I\'ve implemented this tiny decorator:
from functools im
Function composition isn't a super-common operation in Python, especially not in a way that a composition operator is clearly needed. If something was added, I am not certain I like the choice of <<
and >>
for Python, which are not as obvious to me as they seem to be to you.
I suspect a lot of people would be more comfortable with a function compose
, the order of which is not problematic: compose(f, g)(x)
would mean f(g(x))
, the same order as o
in math and .
in Haskell. Python tries to avoid using punctuation when English words will do, especially when the special characters don't have widely-known meaning. (Exceptions are made for things that seem too useful to pass up, such as @ for decorators (with much hesitation) and * and ** for function arguments.)
If you do choose to send this to python-ideas, you'll probably win a lot more people if you can find some instances in the stdlib or popular Python libraries that function composition could have made code more clear, easy to write, maintainable, or efficient.