Skip to content

Instantly share code, notes, and snippets.

@pjaspers
Created June 5, 2014 22:08
Show Gist options
  • Save pjaspers/ec31fc5c2cce175e9ae0 to your computer and use it in GitHub Desktop.
Save pjaspers/ec31fc5c2cce175e9ae0 to your computer and use it in GitHub Desktop.
Let over lambda-ish
func counter() -> (() -> Int) {
var x = 0
func add() -> Int {
x += 1
return x
}
return add
}
var count = counter()
count() // 0
count() // 1
count() // 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment