Producing full list of Fibonacci numbers which fit in an Int I am progressing through the problems listed at projecteuler.com as I learn Scala (my blog where I am covering this experience). I have written a function to produce all the Fibonacci numbers possible in an Int (it's only 47). However, the resulting function feels imperative (not functional).

  val fibsAll = {
    //generate all 47 for an Int
    var fibs = 0 :: List()
    var current = fibs.head
    var next = 1
    var continue = true
    while (continue) {
      current = fibs.head
      fibs = next :: fibs
      continue = ((0.0 + next + current) &lt;= Int.MaxValue)
      if (continue)
        next = next + current
    }
    fibs.reverse
  }


I am looking for feedback on this code:  


To what degree does the presence of even a single var (there are four here) indicate an erred approach from a functional standpoint?
Given I want to return a List[Int], what better way is there to do this recursively as opposed to my current (odd) "while loop" approach?


I am finding the transition from imperative to functional thinking quite challenging.
object Euler002 extends App{
  // Infinite List (Stream) of Fibonacci numbers 
  def fib(a: Int = 0, b: Int = 1): Stream[Int] = Stream.cons(a, fib(b, a+b)) 

  // Take how many numbers you want into a List 
  val fibsAll = fib() takeWhile {_&gt;=0} toList
  fibsAll reverse 
}


Take a look at this.