Anonymous user
Currying: Difference between revisions
→{{header|Swift}}
(add swift) |
|||
Line 567:
20</lang>
=={{header|Swift}}==
▲<lang Swift>func addN(n:Int) -> ((Int) -> Int) {
var add2 = addN(2)
println(add2) // (Function)
println(add2(x:7)) // 9</lang>
There is a bug is 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} }
var add2 = addN(2)
|