book icon indicating copy to clipboard operation
book copied to clipboard

Misleading concepts about iterators in section 17.1

Open zijian-yi opened this issue 6 months ago • 0 comments

  • I have searched open and closed issues and pull requests for duplicates, using these search terms:
    • 17.1
    • iterators
  • I have checked the latest main branch to see if this has already been fixed, in this file:

URL to the section(s) of the book with this problem: https://doc.rust-lang.org/book/ch17-01-futures-and-syntax.html#defining-the-page_title-function

Description of the problem:

In this section it writes:

Iterators do nothing unless you call their next method—whether directly or by using for loops or methods such as map that use next under the hood.

However, this is misleading. Methods like map are just iterator adapters that take in an iterator and output another. Only methods like collect or sum are really iterator consumers that use next under the hood.

Suggested fix:

Change map to collect.

zijian-yi avatar Apr 11 '25 15:04 zijian-yi