Scala - weird behaviour with Iterator.toList <p>I am new to Scala and I have a function as follows:</p> <pre><code>def selectSame(messages: BufferedIterator[Int]) = { val head = messages.head messages.takeWhile(_ == head) } </code></pre> <p>Which is selecting from a buffered iterator only the elems matching the head. I am subsequently using this code:</p> <pre><code>val messageStream = List(1,1,1,2,2,3,3) if (!messageStream.isEmpty) { var lastTimeStamp = messageStream.head.timestamp while (!messageStream.isEmpty) { val messages = selectSame(messageStream).toList println(messages) } </code></pre> <p>Upon first execution I am getting (1,1,1) as expected, but then I only get the List(2), like if I lost one element down the line... Probably I am doing sth wrong with the iterators/lists, but I am a bit lost here.</p>