liveBook · Manning

Chapter 9: Iterators and closures again!

What you will learn in chapter 9 of Learn Rust in a Month of Lunches

The introduction explains why learning more iterator and closure methods is worthwhile and suggests how to approach them without memorizing every method.

After this chapter you will be able to

What it builds on

Section by section

Introduction

The introduction explains why learning more iterator and closure methods is worthwhile and suggests how to approach them without memorizing every method.

Key terms: iterators, closures, methods

9.1 Helpful methods for closures and iterators

This introduction connects comfort with closures to concise method chains and introduces the iterator methods covered next.

Key terms: closures, chain, methods

9.1.1 Mapping and filtering

This section explains how to keep selected iterator items, combine filtering with mapping, and convert between Option and Result when processing values.

Key terms: .filter(), bool, iterator, .filter_map(), Option<T>, Some, None, .ok(), Result<T, E>, Ok

9.1.2 Some more iterator and related methods

This section explains how to work with Option values and discard unsuccessful results while processing iterator items.

Key terms: .and_then(), Option, Some, None, Result, .ok(), .and(), .flatten(), iterator, Err

9.1.3 Checking and finding items inside iterators

This section explains how to test iterator items with .any() and .all(), how item order affects .any(), and how .find() and .position() report matches.

Key terms: .any(), .all(), bool, short circuit, .rev(), .next(), .find(), .position(), Option, Some

9.1.4 Cycling, zipping, folding, and more

This section shows how to combine, consume, inspect, and divide iterators with several useful methods.

Key terms: .cycle(), .zip(), 0.., .fold(), starting value, closure, .by_ref(), .take(), ownership, .chunks()

9.2 The dbg! macro and .inspect

The section shows how to inspect values with dbg! and iterator items with .inspect(), then explains why iterator method chains can read like a sequence of steps.

Key terms: dbg! macro, println!, expression, .inspect(), iterator, closure, item, iterators, closures, method chains

9.3 Summary

Where this is used later

Concepts explained in this chapter

← Chapter 8: Iterators and closures Chapter 10: Lifetimes and interior mutability →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.