Generating Fibonacci sequences in Scala Would you consider this to be idiomatic Scala? If not, what would you do to improve it?

def fibonaccis(max: Int): List[Int] = { fibonaccis(max, 2, 1) }
private def fibonaccis(max: Int, prev: Int, prevPrev: Int): List[Int] = prev &gt;= max match {
  case true =&gt; List[Int](prevPrev)
  case false =&gt; prevPrev :: fibonaccis(max, prev + prevPrev, prev)
}
Naming the parameters prev and prevPrev is weird.  Why not current and prev?

You shouldn't need the curly braces here for a function that consists of a single expression:

def fibonaccis(max: Int): List[Int] = fibonaccis(max, 2, 1)


Conventionally, the Fibonacci sequence is said to start like

$$1, 1, 2, 3, 5, 8, \ldots$$

or

$$0, 1, 1, 2, 3, 5, \ldots$$

Your fibonaccis(13) would produce List(1, 2, 3, 5, 8), which I would consider to be missing the first element.



The Fibonacci sequence is an infinite sequence.  It would be a shame to limit it to a max value.  The most idiomatic way to model it in Scala would be using an infinite lazy stream, just as suggested in the documentation:

def fibFrom(a: Int, b: Int): Stream[Int] = a #:: fibFrom(b, a + b)
val fibonaccis = fibFrom(0, 1)


Alternative implementation:

val fibonaccis: Stream[Int] = 0 #:: 1 #:: fibonaccis.zip(fibonaccis.tail).map(
    n =&gt; n._1 + n._2
)


Then, you could do fibonaccis.takeWhile(_ &lt; 13).toList to obtain List(0, 1, 1, 2, 3, 5, 8).