getLines returns an iterator which I want to split into head and tail.
scala.io.Source.fromFile("somefile").getLines
What’s the correct way to do this?
I want to do something like val (head,tail) = scala.io.Source.fromFile("somefile").getLines().splitAt(1)
But there doesn’t seem to be any such function.
Iterator is not a real collection. It defines next and hasNext and invoking next mutates it. If you want head then go for BufferedIterator or convert the iterator to a real sequence that remembers elements.
Side note: scala.io.Source needs closing, otherwise you could run out of file handles (on any OS) and on Windows keeping the file open means it cannot be deleted.