The Artima Developer Community


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

Page 502 (PDF page 529):
"What’s more, collections are have been adapted to parallel execution on
multi-cores."

should be

"What’s more, collections have been adapted to parallel execution on
multi-cores."

FIXED in 3ed 4th printing
Page 509 (PDF page 536):
"Copies at most len elements of arr, starting at index s. The last two
arguments are optional."

should be

"Copies at most len elements of the collection to arr, starting at
index s. The last two arguments are optional."

FIXED in 3ed 4th printing.
Page 561 (PDF page 540):
In the entry for zipWithIndex, "indicies" should be "indices".

FIXED in 3ed 4th printing.
Page 515 (PDF page 542):
Text says Seq, Set, and Map all implement PartialFunction trait, but it
appears that Set does not actually implement PartialFunction.

FIXED in 4th printing
Page 565 (PDF page 544):
In the entry for lengthCompare, "xs.lengthCompare ys" should be "xs
lengthCompare i". Additionally, the description is wrong (at least for
modern versions of Scala) because "i" must be an Int, not a Seq. The text
should say something like:

"Returns -1 if the length of xs is less than i , +1 if it is greater, and
0 if they are equal. Works even if xs is infinite."

FIXED in 3ed 4th printing. Not sure how that one got through. I looked
back in time and as of 2.7 lengthCompare took an Int.
Page 506 (PDF page 544):
The syntax of "xs.lengthCompare ys" is NOT legal.

Follow the style of the given table in that page, this line should be
"xs lengthCompare ys".

FIXED in 3ed 4th printing
Page 514 (PDF page 552):
The second line after section title.

"Scala’s Predef class offers an implicit conversion that lets you"

Predef is an object, NOT a class.

FIXED in 3ed 4th printing.
Page 515 (PDF page 553):
The operations on sequences, summarized in Figure 24.3, ...

Should be:

The operations on sequences, summarized in Table 24.3, ...

---
Fixed in 5ed. Tnx.
Page 529 (PDF page 556):
Last sentence of first paragraph reads:

You could also have implemented cachedF directly, using just basic map
operations, but it would have have taken more code to do so:

The word 'have' is duplicated and therefore the sentence should read:

You could also have implemented cachedF directly, using just basic map
operations, but it would have taken more code to do so:

FIXED in 3ed 4th printing
Page 529 (PDF page 556):
In discussion of getOrElseUpdate:  "... but it would have have taken ..."

FIXED in 4th printing
Page 541 (PDF page 568):
In discussion of weak hash maps:  "... unreachable, it's entry is removed
..."

FIXED in 4th printing
Page 542 (PDF page 569):
In table 24.9, the description for putIfAbsent should be "Adds key/value
binding k -> v unless k is already defined in m".

FIXED in 3ed 4th printing
Page 543 (PDF page 570):
In the first line, "One the one hand" should be "On the one hand".

Later in the same paragraph, "Scala arrays offer much more their Java
analogues" is missing a "than".

FIXED both in 3ed 4th printing
Page 533 (PDF page 571):
and a pop on a stack is the same a tail on a list  should be:
and a pop on a stack is the same as a tail on a list
---
Fixed in 4ed or 5ed.
Page 564 (PDF page 591):
it sameElements jt -- text (and Scala doc website) says at least one of
the iterators will be at its end after this operation. But if a
difference is found, the iterators will be positioned immediately after
the difference, not necessarily at the end.

FIXED in 4th printing
Page 553 (PDF page 591):
The book shows:
scala> val vv = v.view
vv: scala.collection.SeqView[Int,Vector[Int]] = 
SeqView(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)

But I get:
scala> val vv = v.view
vv: scala.collection.SeqView[Int,scala.collection.immutable.Vector[Int]]
= SeqView(...)
---
Fixed in 4ed.
Page 616 (PDF page 595):
"Internally, these conversion work" should be "Internally, these
conversions work".

FIXED in 3ed 4th printing
Page 559 (PDF page 597):
The book says:
scala> it.next()
res5: java.lang.String = number

But I get the following:
scala> val it = Iterator("a", "number", "of", "words")
it: Iterator[String] = non-empty iterator

scala> it dropWhile (_.length < 2)
res10: Iterator[String] = non-empty iterator

scala> it.next()
res11: String = of

The size method shows the following after the dropWhile:
val it = Iterator("a", "number", "of", "words")
it: Iterator[String] = non-empty iterator

scala> it dropWhile (_.length < 2)
res14: Iterator[String] = non-empty iterator

scala> it.size
res15: Int = 2

So, for some reason it also dropped "number" or the next method skips the
present "number" string.

(Using scala 2.12.4)
----
Yes, fixed in 5ed. Tnx.
Page 559 (PDF page 597):
As I stated in a previous submission, it.next() in the sequence of code
on this page produces:

scala> it.next()
res29: String = of

Upon reviewing the API, I see the reason is because after using
dropWhile:

Reuse:  ...Using the old iterator is undefined...

Thus to return "number" would need to do:

scala> val it = Iterator("a", "number", "of", "words")
it: Iterator[String] = non-empty iterator

scala> val iter = it dropWhile (_.length < 2)
iter: Iterator[String] = non-empty iterator

scala> iter.next()
res28: String = number
---
Fixed in 5ed. Tnx.
Page 594 (PDF page 605):
Not exactly an errata, but...
book talks about JavaConversions and omits any mention of JavaConverters.
Explicit JavaConverters seem to be preferred over implicit
JavaConversions nowadays, so it seems a glaring omission to not mention
JavaConverters here.

---
Fixed in 4ed.

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.