Created
June 5, 2014 22:08
-
-
Save pjaspers/ec31fc5c2cce175e9ae0 to your computer and use it in GitHub Desktop.
Let over lambda-ish
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
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