[Python-Dev] PEP 309 updated slightly (original) (raw)
Alex Naanou alex.nanou at gmail.com
Tue Aug 31 16:51:01 CEST 2004
- Previous message: [Python-Dev] PEP 309 updated slightly
- Next message: [Python-Dev] Re: What is PEP309?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
though this might be a bit late, I would like to suggest something a bit functionally different: ---cut--- class LCurry(object): ''' this is the left curry class. ''' def new(cls, func, *args, **kw): obj = object.new(cls) if isinstance(func, LCurry) or isinstance(func, RCurry): obj._curry_func = func._curry_func obj._curry_args = (func._curry_args[0] + args, func._curry_args[1]) obj._curry_kw = kw = kw.copy() kw.update(func._curry_kw) else: obj._curry_func = func obj._curry_args = (args, ()) obj._curry_kw = kw.copy() return obj def call(self, *args, **kw): self._curry_func(*self._curry_args[0] + args + self._curry_args[1], **dict(self._curry_kw.items() + kw.items()))
--uncut--
this mainly has one thing different from the reference implementation in the pep:
- it is recursive that is we can curry/partial something more than one and yet avoid the extra function call per curry level...
IMO this is a worthwhile optimisation....
taken from: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/222061
- Previous message: [Python-Dev] PEP 309 updated slightly
- Next message: [Python-Dev] Re: What is PEP309?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]