Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
C HAPTER 24 ยท The Scala Collections API not have side effects. Or you apply them over mutable collections where all modifications are done explicitly. What's best avoided is a mixture of views and operations that create new collections while also having side effects. 24.16 Iterators An iterator is not a collection, but rather a way to access the elements of a collection one by one. The two basic operations on an iterator it are next and hasNext . A call to it.next() will return the next element of the iterator and advance the state of the iterator. Calling next again on the same iterator will then yield the element one beyond the one returned pre- viously. If there are no more elements to return, a call to next will throw a NoSuchElementException . You can find out whether there are more ele- ments to return using Iterator 's hasNext method. The most straightforward way to "step through" all the elements returned by an iterator is to use a while loop: while (it.hasNext) println(it.next())