currying with Python object methods
December 2nd, 2002
Today’s Python codesnippet (actually from Nov. 14th, but the mail daemon got in the way) courtesy yours truly:
# objcurry: called with an object and
# the name of a method, will return
# a standalone function that can be
# called at any time (as if it were
# still connected to its object).
# (requires python2.2 or later)
def objcurry(object, methodname):
def curried(*args, **kargs):
apply(getattr(object,methodname), args, kargs)
return curried