Archive for December, 2010

In a recent project, I’ve experimented with “partial()” to simplify object creation. Partially applying a function, similar to currying, is a technique in which a new function is synthesized by pre-filling the arguments to an existing function. Python’s implementation of partial is available in two separate modules: functools and functional. It’s best understood with an example, albeit contrived:

Instead of defining a factory class and a creation method on that class, I define creation function which accepts the dependencies as parameters, partially apply them and use the new function as my “creation function.” I prefer the second example, I enjoyed writing it, but both examples perform the same function with essentially the same number of lines and ultimately my preference is as basic as preferring a functional style of programming over object oriented.

So I’m wondering, how do other developers use currying or partial application in their projects?

Search