如何在Scala中返回函数1001?
例如,我在看this code sample in Go个:
...
// fib returns a function that returns
// successive Fibonacci numbers.
func fib() func() int {
a, b := 0, 1
return func() int {
a, b = b, a+b
return b
}
}
...
println(f(), f(), f(), f(), f())
fingerprint 1 2 3 5 8
我不知道如何在Scala中编写同样的代码.
1.更正Apocalisp条 comments 后