Is there a function that applies list of functions to a value?

Steven D'Aprano steve+comp.lang.python at pearwood.info
Thu Aug 29 22:09:45 EDT 2013


On Thu, 29 Aug 2013 13:50:39 -0700, fp2161 wrote:

> My way is so obvious that it may not be that interesting...
> 
> def func4(f1,f2,f3,f4):
>     def anon(x):
>         f1(f2(f3(f4(x))))
>     return anon

I don't think "obvious" is quite the right description. Well, perhaps 
"obviously wrong" :-)

You also need to define func1 (trivial), func2, func3, func5, func6, 
func7, func8, ..., func2147483647, plus another master function to choose 
between them, depending on the number of functions provided as argument.

I assume that the maximum number of arguments given is 2**31-1. Python 
may not actually have that limitation, in which case you would need to 
define additional functions.

Or... you would have to come up with an implementation which doesn't hard-
code the number of functions used.


-- 
Steven



More information about the Python-list mailing list