Hi Matteo,
Is there any way to suppress the output of a large list?
That happens automatically (see below)
I just came across the issue, in the code below the iterator is lost after an output error
You can't go through this interator twice. Once you do words.length, the iterator has advanced to its end. The next words.toList gives you an empty list, and a subsequent words.length returns 0.
If you 'save' the interator's contents in a sequence, you can get the sequence's length multiple times without a problem. See below:
import scala.io._ //> import scala.io._
val in = Source.fromFile("/home/lalit/Scratch/lw.txt") //> in: scala.io.BufferedSource = non-empty iterator
val words = in.getLines //> words: Iterator[String] = non-empty iterator
val wordList = words.toList //> wordList: List[String] = List(This is a line in a file. This is another line in a file., This is a line in a file. This is another line in a file., This is a line in a file. This is another line in a file., This is a line in a file. This is another line in a file., This is a line in a file. This is another line in a file., This is a line in a file. This is another line in a file., This is a line in a file. This is another line in a file., This is a line in a file. This is another line in a file., This is a line in a file. This is another line in a file., This is a line in a file. This is another line in a file., This is a line in a file. This is another line in a file., This is a line in a file. This is another line in a file., This is a line in a file. This is another line ...
wordList.length //> res12: Int = 33024
val wordVec = wordList.toVector //> wordVec: Vector[String] = Vector(This is a line in a file. This is another line in a file., This is a line in a file. This is another line in a file., This is a line in a file. This is another line in a file., This is a line in a file. This is another line in a file., This is a line in a file. This is another line in a file., This is a line in a file. This is another line in a file., This is a line in a file. This is another line in a file., This is a line in a file. This is another line in a file., This is a line in a file. This is another line in a file., This is a line in a file. This is another line in a file., This is a line in a file. This is another line in a file., This is a line in a file. This is another line in a file., This is a line in a file. This is another li...
wordList.length //> res13: Int = 33024
Does that make sense? Please verify with your test case.
/L