exercises-scalatutorial icon indicating copy to clipboard operation
exercises-scalatutorial copied to clipboard

Suggest using `toList` instead of `to(List)`

Open agam opened this issue 6 years ago • 0 comments

As an example, on OSX with Scala version 2.13.1, I see

scala> def average(x: Int, xs: Int*): Double =
     | (x :: xs.to(List)).sum.toDouble / (xs.size + 1)
<console>:13: error: type mismatch;
 found   : scala.collection.immutable.List.type
 required: scala.collection.generic.CanBuildFrom[Nothing,Int,?]
       (x :: xs.to(List)).sum.toDouble / (xs.size + 1)
                   ^

agam avatar Feb 26 '20 06:02 agam