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

Raymond Hettinger python at rcn.com
Tue Feb 3 22:16:21 CET 2009


>>> I still haven't seen any real code presented that would benefit from
>>> partial.skip or partial_right.

# some Articles have timestamp attributes and some don't
stamp = partial_right(getattr, 'timestamp', 0)
lastupdate = max(map(stamp, articles))

# some beautiful soup nodes have a name attribute and some don't
name = partial_right(getattr, 'name', '')
alltags = set(map(name, soup))



>> The arguments for and against the patch could be brought against partial()
>> itself, so I don't understand the -1's at all.
> 
> Quite so, but that doesn't justify adding more capabilities to partial().

I concur with Collin.  Lever arguments are a road to bloat.
"In for a penny, in for a pound" is not a language design principle.

One of the real problems with partial() and its variants is that they provide
almost no advantage over an equivalent lambda.  IMO, lambda has
an advantage over partial.skip() because the lambda is easier to read:
  
   modcubes = lambda base, mod:   pow(base, 3, mod)


Raymond


More information about the Python-Dev mailing list