The Artima Developer Community


Errata for Programming in Scala, 4th Edition
Chapter 24: Collections in Depth
Return to errata index.

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.

Page number: Book type: Paperback book PDF eBook
Book version: (Or build date. Found on back of title page.)
Your feedback:
Your name: (optional)
Your email address: (optional) (will not be published)

Copyright © 2021 Artima, Inc. All rights reserved.