Skip to content

Instantly share code, notes, and snippets.

@nathanhillyer
Last active January 8, 2016 17:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nathanhillyer/4d046e8651d8664a4ed1 to your computer and use it in GitHub Desktop.
Save nathanhillyer/4d046e8651d8664a4ed1 to your computer and use it in GitHub Desktop.
// 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