Enter your book access code

The curriculum, drills, tutor, and interviewer mode are for readers of Ace the Rust Interview. The code is printed in the Preface (Companion site access).

Don’t have the book yet? The landing page stays open — purchase unlocks this gym.

intermediate · order 181

Lazy adapter chain

iter-adapter-01Related book chapters: 9 (optional — this page is complete on its own)iteratorlazyadapter

Slug: iter-adapter-01 · Paired reading: Chapter 9

Prompt

Implement fn sum_evens_doubled(xs: &[i32]) -> i32 as an iterator pipeline: keep even values, double them, sum. Do not allocate an intermediate Vec.

Contract

  • Empty input → 0
  • Negatives are fine (-2 is even)
  • Must be expressible as adapters + consumer (no manual for required, but allowed if equivalent)

Predict first

Does xs.iter().filter(...).map(...) run before sum()? Why?

Rust angle

Adapters are lazy; work happens at the consumer. Interviewers probe whether you treat the chain as a snapshot or a borrow of xs.