I came across a pretty clever little function that takes two functions, applies one on top of each other given an argument x
:
def compose(f,g):
return lambda *x: f(g(*x))
Now my issue is with *x
, as I don't see it really doing anything here. Why couldn't it be simple x
(without the asterisk)?
Here are my tests:
>>> def compose(f,g):
... return lambda *x: f(g(*x))
...
>>> this = lambda i: i+1
>>> that = lambda b: b+1
>>> compose(this,that)(2)
4
>>> def compose(f,g):
... return lambda x: f(g(x))
...
>>> compose(this,that)(2)
4
>>> def compose(f,g):
... return lambda *x: f(g(*x))
...
>>> compose(this,that)(2,2)
TypeError: <lambda>() takes exactly 1 argument (2 given)