[Python-Dev] functools.compose to chain functions together

Steven D'Aprano steve at pearwood.info
Sun Aug 16 14:14:56 CEST 2009

On Sat, 15 Aug 2009 04:39:03 am Jason R. Coombs wrote:

> I'd like to express additional interest in python patch 1660179,
> discussed here:
> http://mail.python.org/pipermail/patches/2007-February/021687.html
> But to me, a compose function is much easier to read and much more
> consistent with the decorator usage syntax itself.
> def meta_decorator(data):
>     return compose(dec_register_function_for_x, dec_alter_docstring,
>     dec_inject_some_data(data))

Surely that's better written as:

meta_decorator = compose(dec_register_function_for_x,
    dec_alter_docstring, dec_inject_some_data)

> I admit, I may be a bit biased; my first formal programming course
> was taught in Scheme.

Mine wasn't -- I've never even used Scheme, or Lisp, or any other 
functional language. But I've come to appreciate Python's functional 
tools, and would like to give a +0.5 to compose(). +1 if anyone can 
come up with additional use-cases.

Steven D'Aprano

More information about the Python-Dev mailing list