[Python-Dev] Partial function application 'from the right'

Leif Walsh leif.walsh at gmail.com
Thu Jan 29 22:58:25 CET 2009


On Thu, Jan 29, 2009 at 9:12 AM, Ben North <ben at redfrontdoor.org> wrote:
> I find 'functools.partial' useful, but occasionally I'm unable to use it
> because it lacks a 'from the right' version.  E.g., to create a function
> which splits a string on commas, you can't say

First of all, many functions like this are easy to handle yourself.  Example:

>>> def split_comma(s):
>>>   return str.split(s, ',')

That said, it seems to me that if we're going to add to
functools.partial, we should go all the way and allow keyword
arguments (or a dict of them, if it's otherwise too hard to
implement).  Otherwise, in another few {days, weeks, months} we'll see
another thread like this clamoring for a keyword-sensitive
functools.partial.

Come to think of it, I would imagine the next iteration would ask for
a way to curry arbitrary positional arguments, and I can't come up
with a simple and beautiful way to do that off the top of my head.
Maybe this is an argument for keeping functools.partial the way it is
and forcing developers to write their own currying functions.

-- 
Cheers,
Leif


More information about the Python-Dev mailing list