class foo(object):
def __init__(self,f):
self.f = f
def __call__(self,args_list):
def wrapped_f(args_list):
return [self.f(*args) for args in args_list]
return wrapped_f(args_list)
if __name__=='__main__':
class abc(object):
@foo
def f(a,b,c):
return a+b+c
a = range(5)
b = range(5)
c = range(5)
data = list(zip(a,b,c))
print(abc.f(data))
I wrote this a few years back. When you decorate any function f(X)
with @foo
it becomes
f(list of Xs)
.
What is this process called? What is it? What is its functional programming name?
Its not currying. I know simple map9(f,list of Xs)
could have done it.
What are decorators/operation of decorating called mathematically?
There are two transformations performed on your original function:
First transformation
In Haskell, there is a function called
uncurry
, documented here. (This is a two-argument version; 3-, 4-, ... versions could be easily created, too).Second transformation
Also in Haskell, there are sets of functions with
lift
in their names. Here's a page on the Haskell wiki about lifting. I think that page explains it better than I could:So in your case, you're lifting a function from operating on tuples to operating on a list of tuples.
Notes: