Last active
January 8, 2016 17:09
-
-
Save nathanhillyer/4d046e8651d8664a4ed1 to your computer and use it in GitHub Desktop.
This file contains 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
// The return value of this function is () -> Int | |
// This means we are returning a function that returns an Int | |
func makeIncrementer(forIncrement amount: Int) -> () -> Int { | |
var runningTotal = 0 | |
// Nested function that uses the runningTotal variable | |
func incrementer() -> Int { | |
runningTotal += amount | |
return runningTotal | |
} | |
// We are returning the nested incrementer function without executing it | |
// This means that consumers of the makeIncrementer method may execute | |
// the inrementer function at any point in the future | |
return incrementer | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment