Not tested

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
val fib: (Int, Int => Boolean) => List[Int] =
{
(n, p) => {
val f: (Int, Int => Boolean, Int, Int, Int) => List[Int] = {
case (n, p, a, b) if (a + b > n) => Nil
case (n, p, a, b) if (p(a + b)) => (a + b)::f(n, p, b, a + b)
case (n, p, a, b) => f(n, p, b, a + b)
}
f(n, p, 1, 0)
}
}