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

Ryan Gonzalez rymg19 at gmail.com
Tue May 31 11:35:12 EDT 2016


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/
On May 31, 2016 8:04 AM, "Yongsheng Cheng" <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
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/0323976d/attachment.html>


More information about the Python-ideas mailing list