Hi,
I am implementing lazy list using the example in the book FP in Scala and I found that it fails when I try to search for prime numbers in fibonacci series. The issue seem to be with filter implementation. If I replace the filter implementation using foldRight with pattern matching, then it seems to work fine.
This is how I am checking for primes on fibonacci
Stream fibs = Stream[BigInt](0, 1) append unfold[BigInt, (BigInt, BigInt)]((0, 1))(_ match { case (a, b) => Some((a + b, (b, a + b))) }) println(fibs.filter(_.isProbablePrime(8)).drop(21).headOption)
Here is my implementation (which is identical to Stream implementation in the book and two filter implementation
1) 'filter' with pattern matching which works and
2) 'filter_overflow' which is like the one in the book and overflows)
Any ideals?
Thanks
Prateem