Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><code>Source.getLines()</code> returns an <code>Iterator</code>, and walking through an <code>Iterator</code> will mutate it. This is made quite clear in the <a href="http://www.scala-lang.org/api/current/index.html#scala.collection.Iterator" rel="nofollow">Scala documentation</a></p> <blockquote> <p>An iterator is mutable: most operations on it change its state. While it is often used to iterate through the elements of a collection, it can also be used without being backed by any collection (see constructors on the companion object).</p> <p>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.</p> </blockquote> <p>Using <code>for</code> notation is just syntactic sugar for calling <code>map</code>, <code>flatMap</code> and <code>foreach</code> methods on the Iterator, which again have quite clear documentation stating not to use the iterator:</p> <blockquote> <p>Reuse: After calling this method, one should discard the iterator it was called on, and use only the iterator that was returned. Using the old iterator is undefined, subject to change, and may result in changes to the new iterator as well.</p> </blockquote> <p>Scala generally aims to be a 'pragmatic' language - mutation and side effects are allowed for performance and inter-operability reasons, although not encouraged. To call it 'well-hidden' is, however, something of a stretch.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload