Skip to content

Instantly share code, notes, and snippets.

@qoelet
Created September 19, 2011 01:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save qoelet/1225838 to your computer and use it in GitHub Desktop.
Save qoelet/1225838 to your computer and use it in GitHub Desktop.
## {{{ http://code.activestate.com/recipes/52549/ (r3)
class curry:
def __init__(self, fun, *args, **kwargs):
self.fun = fun
self.pending = args[:]
self.kwargs = kwargs.copy()
def __call__(self, *args, **kwargs):
if kwargs and self.kwargs:
kw = self.kwargs.copy()
kw.update(kwargs)
else:
kw = kwargs or self.kwargs
return self.fun(*(self.pending + args), **kw)
## end of http://code.activestate.com/recipes/52549/ }}}
def myMax(x,y):
if x > y:
return x
elif y > x:
return y
else:
return -1
if __name__ == "__main__":
myMax2 = curry(myMax,4)
print myMax2(6)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment