According to scala, the docs stream implements lazy lists where items are evaluated only when they are needed. Example
val fibs: Stream[BigInt] = BigInt(0)
n._1 + n._2
})
After that in scala repl;
fibs(4)
fibs
Will be printed;
res1: stream [BigInt] = stream (0, 1, 1, 2, 3 ,?)
Since calling .length or .last causes an infinite loop, how can I get the value "3" (the last calculated value) in the most efficient way?
source
share