swift的柯里化demo

func baseFunc(go:String, goo:String) -> String {

        return "hello" + go + goo;

    }

    

    func CurryFunc(baseFun:@escaping (String,String)->String) ->(String) -> (String)->String {

        func returnFun(other:String)->(String)->String{

            func inReturnFun(inner:String) -> String{

                return baseFun(inner,other);

            }

            return inReturnFun;

        }

        

        return returnFun;

    }

 

       let e = self.CurryFunc(baseFun: baseFunc)("fist");

        

        print(e);

        

        let x = self.CurryFunc(baseFun: baseFunc)("fist")("otehr");

        

        print(x);

        

        let go = self.CurryFunc(baseFun: { (a, b) -> String in

            return a + b;

        });

 

e () -> () 0x0000000105848190 FunctionGoo`partial apply forwarder for

 inReturnFun #1 (inner: Swift.String) -> Swift.String

in returnFun #1 (other: Swift.String) -> (Swift.String) -> Swift.String

in FunctionGoo.ViewController.CurryFunc(baseFun: (Swift.String, Swift.String) -> Swift.String) -> (Swift.String) -> (Swift.String) -> Swift.String

at <compiler-generated>

posted @ 2019-08-16 18:38  zzfx  阅读(286)  评论(0编辑  收藏  举报