Currying: Difference between revisions
Content added Content deleted
Line 572: | Line 572: | ||
println(add2) // (Function) |
println(add2) // (Function) |
||
println(add2(x:7)) // 9</lang> |
println(add2(x:7)) // 9</lang> |
||
There is a bug |
There is a bug in Swift (as of 1.1) which forces the second parameter to always be labeled. To avoid it, you can return a closure (or nested function): |
||
<lang Swift>func addN(n:Int)->Int->Int { return {$0 + n} } |
<lang Swift>func addN(n:Int)->Int->Int { return {$0 + n} } |
||