Solution (source code)

= Solution

Use a <programming closure> whose private variable holds the next <Fibonacci number>. Use <arbitrary-precision integers> to enumerate all terms exactly:
``
def fibonacci(): Iter[BigInt] = {
  var following = BigInt(1)
  val step: BigInt => BigInt = (current: BigInt) => {
    val result = following
    following = current + following
    result
  }
  new FunIter[BigInt](BigInt(0), step)
}
``
At the cell containing $F_i$, the private state immediately before computing its successor is `following = F_(i+1)`. The successor returns that value and sets `following` to $F_i+F_{i+1}=F_{i+2}$, preserving the <recursion invariant>. The resulting <sequence> starts
$$
\boxed{0,1,1,2,3,5,8,13,21,34,\ldots.}
$$
Each successor is computed once by the memoized implementation in part (c); interleaved copies see the same already generated successor instead of independently advancing shared <programming closure> state. Replacing `BigInt` by `Int` and the two initial values by `0,1` gives exactly the hinted `Int => Int` implementation, but eventually incurs <integer overflow>, so it does not enumerate all mathematical <Fibonacci numbers>.

An alternative avoiding mutable <programming closure> state represents the current and next <Fibonacci numbers> by a <pair> $(a,b)$ and uses the <pure function> $(a,b)\mapsto(b,a+b)$ with initial state $(0,1)$; a projecting <iterator> returns the first component. The closure construction above meets the suggested one-number interface directly.