A fib sequence can be defined corecursively using unfold and its actually a nice way to write it in some languages.
Here is the next fib in a sequence (in psuedocode):
(a, b) -> (a, (b, a+b))
And then you can get a sequence with unfold by giving it some starting numbers: val fibonacci: Iterator[Int] =
Iterator.unfold((1, 1)) {
case (x, y) => Some((x, (y, x + y)))
}
(That is Scala. But lots of languages have an unfold method) > fibonacci.take(8).toList
1, 1, 2, 3, 5, 8, 13, 21