Swift 4.0 废弃的柯里化

// 柯里化 

// http://www.jianshu.com/p/6eaacadafa1a                               Swift 2.0 柯里化方法 (废弃)

// http://www.swifthumb.com/thread-16079-1-1.html                      Swift 3.0 柯里化常用方法推荐

// http://www.ruanyifeng.com/blog/2012/04/functional_programming.html  函数式编程

/*

 Curried function declaration syntax func foo(x: Int)(y: Int) is of limited usefulness and creates a lot of language and implementation complexity. We should remove it.

 

 (函数的 currying 特性的使用场景并不大,但他会增加很多语言的复杂性,所以需要删除它)

 */

 

 1 class Currying
 2 
 3 {
 4 
 5     // uncurried:普通函数
 6 
 7     // 接收多个参数的函数(与类相关的函数,统称为方法,但是这里就直接说函数了,方便理解)
 8 
 9     func add(a: Int, b: Int, c: Int) -> Int{
10 
11         print("\(a) + \(b) + \(c)")
12 
13         return a + b + c
14 
15     }
16 
17     
18 
19     // curried:柯里化函数 --> 本质函数式编程思想
20 
21     func addCur(_ a: Int) -> (Int) -> (Int) -> Int{
22 
23         return {
24 
25             b in
26 
27             return {
28 
29                 c in
30 
31                     a + b + c
32 
33             }
34 
35         
36 
37         }
38 
39     }
40 
41 }
42 
43  
44 
45 let curry = Currying()
46 
47 var number = Currying.addCur(curry)(12)(23)(12)
48 
49 print(number)
50 
51  
52 
53 // NO.2
54 
55 let datePrint:(Int)->(Int)->(String)->Void =
56 
57 {
58 
59     month in
60 
61     print("\(month)月")
62 
63     return{
64 
65         day in
66 
67         print("\(day)日")
68 
69         return{
70 
71             action in
72 
73             print("\(action)")
74 
75         }
76 
77     }
78 
79 }
80 
81 let actionPrint = datePrint(2016)(11)
82 
83 actionPrint("写详细")
84 
85  

 

转载于:https://www.cnblogs.com/lurenq/p/7416528.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值