jweinst1
6/1/2016 - 11:35 PM

javascript style closures in swift

javascript style closures in swift

//swift closure implementation relative to javascript

//makes a function that adds some number to another number
func makeaddfunc(amount:Int) -> (Int) -> Int {
    return {(num:Int) -> Int in num + amount}
}

let adder = makeaddfunc(4)
print(adder(4))
//8