[Python-ideas] A function currying decorator ((Was: no subject))

Ed Minnix egregius313 at gmail.com
Tue May 31 17:09:30 EDT 2016


It requires downloading a 3rd party package, but both toolz and funcy provide curry classes/functions which can decorate a function and create a function that is automatically curried.

- Ed

> On May 31, 2016, at 11:59 AM, Yongsheng Cheng <cyscoyote at gmail.com <mailto:cyscoyote at gmail.com>> wrote:
> 
> Yes, that's what I meant. thanks and do you think we need such decorate in funtools? wiatting for reply 
> 
> Ryan Gonzalez <rymg19 at gmail.com <mailto:rymg19 at gmail.com>>于2016年5月31日周二 下午11:35写道:
> So you're referring to function currying, correct? I changed the thread title to reflect that.
> 
> --
> Ryan
> [ERROR]: Your autotools build scripts are 200 lines longer than your program. Something’s wrong.
> http://kirbyfan64.github.io/ <http://kirbyfan64.github.io/>
> On May 31, 2016 8:04 AM, "Yongsheng Cheng" <cyscoyote at gmail.com <mailto:cyscoyote at gmail.com>> wrote:
> to begin with: i a deep python fun
> i want to suguest python a feature to support Fuctional Program :,here is the toy code  i need a more powerful decrote in moudle functools instead of functools.partial,thanks do you think it is a nice idea?
> waitting for your reply
> 

> On May 31, 2016, at 11:59 AM, Yongsheng Cheng <cyscoyote at gmail.com> wrote:
> 
> Yes, that's what I meant. thanks and do you think we need such decorate in funtools? wiatting for reply 
> 
> Ryan Gonzalez <rymg19 at gmail.com <mailto:rymg19 at gmail.com>>于2016年5月31日周二 下午11:35写道:
> So you're referring to function currying, correct? I changed the thread title to reflect that.
> 
> --
> Ryan
> [ERROR]: Your autotools build scripts are 200 lines longer than your program. Something’s wrong.
> http://kirbyfan64.github.io/ <http://kirbyfan64.github.io/>
> On May 31, 2016 8:04 AM, "Yongsheng Cheng" <cyscoyote at gmail.com <mailto:cyscoyote at gmail.com>> wrote:
> to begin with: i a deep python fun
> i want to suguest python a feature to support Fuctional Program :,here is the toy code  i need a more powerful decrote in moudle functools instead of functools.partial,thanks do you think it is a nice idea?
> waitting for your reply
> 
> def minpara(func_1,args):
>      num=0
>      try:
>          func_1(*args)
>      except Exception as error:
>          num,given=re.findall(r'\d+',str(error))[:2]
>      if num:
>         #return int(num),int(given)
>          return (num,given)
>      else:
>          #return func(*args)
>          return (0,0)
> 
> def curried(func):
>     #@wraps(func)
>     def new_func(*args):
>         num,given=minpara(func,args)
>         #print num,given
>         if (num,given)==(0,0):
>             return func(*args)
>         else:
>             return curried(functools.partial(func,*args))
>     return new_func
> @curried   
> def sun_1(a,b,c):
>     return a+b+c
> @curried
> def sun_2(a,b,c):
>      return a*b*c
> if __name__=="__main__":
>     print sun_2(1,)(2)(44)
>     print sun_1(1,)(2)(44)
>     print sun_2(1,2)(23)
> 
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org <mailto:Python-ideas at python.org>
> https://mail.python.org/mailman/listinfo/python-ideas <https://mail.python.org/mailman/listinfo/python-ideas>
> Code of Conduct: http://python.org/psf/codeofconduct/ <http://python.org/psf/codeofconduct/>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20160531/93601167/attachment.html>


More information about the Python-ideas mailing list