Last active
December 24, 2015 18:50
-
-
Save tanishiking/dcfdc8e08596fc99e4d1 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
object MyGenerator { | |
def main(args: Array[String]) = { | |
val g = myGenerator() | |
println(g()) // 1 | |
println(g()) // 2 | |
println(g()) // 3 | |
} | |
private[this] def myGenerator(): (() => Int) = { | |
var num = 0 // 局所変数 | |
() => { // 評価される関数 | |
num += 1 | |
num | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment