Source.getLines()
returns an iterator. For every iterator, if you invoke a bulk operation such as foreach
above, or map
, take
, toList
, etc., then the iterator is no longer in a usable state.
That is the contract for Iterator
s and, more generally, classes that inherit TraversableOnce
.
It is of particular importance to note that, unless stated otherwise, one should never use an iterator after calling a method on it. The two most important exceptions are also the sole abstract methods: next and hasNext.
This is not the case for classes that inherit Traversable
-- for those you can invoke the bulk traversal operations as many times as you want.