Currying a lifted function using python toolz

54 Views Asked by At

I am

  • defining a function of 3 variables,
  • lifting it to a function on list,
  • then currying that lifted function,
  • applying the first two arguments lists
  • Finally applying the last argument

The code is as following :

from toolz.curried import map, curry

# Defining a function of 3 variables
def f(x, y, z):
    return x + y + z

# Lifting to a function on lists
g = map(f)

# Currying the lifted function
h = curry(g)

# Applying the first 2 list arguments
i = h([1,2,3],[4,5,6])

# Applying the last argument
print(i([7,8,9]))

I get the error :

Traceback (most recent call last):
  File "C:\Users\johnsmith\try.py", line 17, in <module>
    print(i([7,8,9]))
TypeError: 'map' object is not callable

I am not really looking for an other way to solve the problem, but more understanding conceptually, why is this not working?

0

There are 0 best solutions below