Text: "On the infinite list, one match is found, so the call [to anyMatch()] terminates. If we called noneMatch() or allMatch(), they would run until we killed the program."
This is incorrect. noneMatch() also terminates immediately, returning false. Apart from that, I would say the term "infinite list" is incorrect and should read "infinite stream".
I think there is something a little bit confusing with that paragraph. Granted, it is true that this would terminate:
But this, I think, would not:
And although it is never said in the paragraph that the noneMath() method ALWAYS terminates, the correction may lead someone to (mistakenly) assume that it does (I almost did).
posted 1 year ago
Yes, I realize that first paragraph states that those methods “may or may not terminate for infinite stream”. So there is no errata in there. Mine was just a friendly note on the perhaps confundent (?) feeling I get when reading that section + the corrected errata.
Jorge Ruiz-Aquino wrote:In the last paragraph of allMatch(), anyMatch() and noneMatch().
"noneMatch() also returns false because one matches" should say "noneMatch() also returns false because two match"
It's right as is. As soon as noneMatch() sees a match, it stops looking. There could be one or a million. It's only the first match that matters.