"""This class is a curry (think functional programming)."""
__docformat__ = "restructuredtext"
# Created: Mon May 10 16:49:56 PDT 2004
# Author: Shannon -jj Behrens
# Email: jjinux@users.sourceforge.net
#
# Copyright (c) Shannon -jj Behrens. All rights reserved.
class Curry:
"""This class is a curry (think functional programming).
HACK: This class can probably go away in Python 2.3 thanks to closures.
The following attributes are used:
f
This is the function being curried.
initArgs, initKargs
These are the args and kargs to pass to ``f``.
"""
def __init__(self, f, *initArgs, **initKargs):
"""Accept the initial arguments and the function."""
self.f = f
self.initArgs = initArgs
self.initKargs = initKargs
def __call__(self, *args, **kargs):
"""Call the function."""
updatedArgs = self.initArgs + args
updatedKargs = self.initKargs.copy()
updatedKargs.update(kargs)
return self.f(*updatedArgs, **updatedKargs)
|