Currying decorator in python

前端 未结 9 1798
故里飘歌
故里飘歌 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 03:47

    As it's cool to write currying decorators in python, I tried mine: 5 lines of code, readable, and tested curry function.

    def curry(func):
        def curried(*args, **kwargs):
            if len(args) + len(kwargs) >= func.__code__.co_argcount:
                return func(*args, **kwargs)
            return (lambda *args2, **kwargs2:
                    curried(*(args + args2), **dict(kwargs, **kwargs2)))
        return curried
    

提交回复
热议问题