// 柯里化 html
// http://www.jianshu.com/p/6eaacadafa1a Swift 2.0 柯里化方法 (廢棄)編程
// http://www.swifthumb.com/thread-16079-1-1.html Swift 3.0 柯里化經常使用方法推薦swift
// 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.spa
(函數的 currying 特性的使用場景並不大,但他會增長不少語言的複雜性,因此須要刪除它)code
*/htm
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