the following code takes almost forever:
val r =(1 to 10000)
.map(_ => Seq.fill(10000)(0.0))
.map(_.size)
.sum
While this is very fast:
val r =(1 to 10000)
.map(_ => Seq.fill(10000)(0.0).size)
.sum
Why is that? I don't quit understand in which order the statements are executed. In the first case, are first 10000 Seqs of size 10000 created, and then all those mapped to the size? Or is each Seq mapped to the size individually (and thus garbage-collected)?