Created
May 15, 2021 14:41
-
-
Save Ochornma/1e93b135201e999d69b3b6f85d148990 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let plus: (Int, Int) -> Int = { | |
return $0 + $1 | |
} | |
let minus: (Int, Int) -> Int = { | |
return $0 - $1 | |
} | |
let add: (Int, Int) -> Int = { | |
return $0 + $1 | |
} | |
let subtract: (Int, Int) -> Int = { | |
return $0 - $1 | |
} | |
let closureFunctions = [ plus, minus ] | |
let plusSign = closureFunctions[0] | |
print(plusSign(1, 5)) | |
//result is: | |
//6 | |
//The append method | |
closureFunctions.append(add) | |
closureFunctions.append(subtract) | |
print(closureFunctions.count) | |
//result is: | |
//4 | |
for closure in closureFunctions { | |
print(closure(6,5)) | |
} | |
//result is: | |
//11 | |
//1 | |
//11 | |
//1 | |
let addition: (Int, Int) -> Int = { | |
return $0 + $1 | |
} | |
let subtraction: (Int, Int) -> Int = { | |
return $0 - $1 | |
} | |
let closureFunctions2= [ addition, subtraction ] | |
let newClosureFunction = closureFunctions + closureFunctions2 | |
print(newClosureFunction.count) | |
//result is: | |
//6 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment