Credit: Scott David Daniels, Nick Perkins, Alex Martelli, Ben Wolfson, Alex Naanou, David Abrahams, Tracy Ruggles
You need to wrap a function (or other callable) to get another callable with fewer formal arguments, keeping given values fixed for the other arguments (i.e., you need to curry a callable to make another).
Curry is not just a delightful spice used in Asian cuisine—it's also an important programming technique in Python and other languages:
def curry(f, *a, **kw): def curried(*more_a, **more_kw): return f(*(a+more_a), **dict(kw, **more_kw)) return curried
Popular in functional programming, currying is a way to bind some of a function's arguments and wait for the rest of them to show up later. Currying is named in honor of Haskell Curry, a mathematician who laid some of the cornerstones in the theory of formal systems and processes. Some pedants (and it must be grudgingly admitted they have a point) claim that the technique shown in this recipe should be called partial application, and that "currying" is something else. But whether they're right or wrong, in a book whose title claims it's a cookbook, the use of curry in a title was simply irresistible. Besides, the use of the verb to curry that this recipe supports is the most popular one among programmers.
curry function defined in this recipe is invoked with a callable and some or all of the arguments to the callable. (Some people like to ...