Created
September 19, 2011 01:51
-
-
Save qoelet/1225838 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## {{{ 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