Currying decorator in python

前端 未结 9 1802
故里飘歌
故里飘歌 2020-12-03 03:11

I am trying to write a currying decorator in python, and I think I\'ve got the general idea down, but still got some cases that aren\'t working right...

def          


        
9条回答
  •  死守一世寂寞
    2020-12-03 04:06

    One-liner just for fun:

    from functools import partial
    curry = lambda f: partial(*[partial] * f.__code__.co_argcount)(f)
    
    @curry
    def add(x, y, z):
        return x + y + z
    
    print(add(2)(3)(4))
    # output = 9
    

提交回复
热议问题