Page 1082 (PDF page 1120):
I think there is an issue with the code sample involving iterators
and dropwhile.
scala> val it = Iterator("a", "number", "of", "words")
it: Iterator[java.lang.String] = <iterator>
scala> it dropWhile (_.length < 2)
res4: Iterator[java.lang.String] = <iterator>
scala> it.next()
res5: java.lang.String = number
The book states that after the call to dropWhile, the iterator "it"
points to "number". This is not the case when I run this code in the
Scala REPL or in a script. It instead points to "a". It looks like the
call creates an independent iterator which points to "number". I
wrote this to verify:
val it2 = it dropWhile (_.length < 2)
println(it2.next()) // prints "number"
----
True. Fixed this in 5ed. Tnx.
|