Skip to content

Commit ded2370

Browse files
author
David Elliott
committed
clarify that find returns first match
the example for `find` was misleading in that it fails to mention the result is either `None` or `Some` containing only the first match. Further confusing the issue is the `println!` statement, "We got some numbers!"
1 parent 2e88c36 commit ded2370

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/doc/trpl/iterators.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,15 +150,16 @@ let greater_than_forty_two = (0..100)
150150
.find(|x| *x > 42);
151151

152152
match greater_than_forty_two {
153-
Some(_) => println!("We got some numbers!"),
154-
None => println!("No numbers found :("),
153+
Some(_) => println!("Found a match!"),
154+
None => println!("No match found :("),
155155
}
156156
```
157157

158158
`find` takes a closure, and works on a reference to each element of an
159159
iterator. This closure returns `true` if the element is the element we're
160-
looking for, and `false` otherwise. Because we might not find a matching
161-
element, `find` returns an `Option` rather than the element itself.
160+
looking for, and `false` otherwise. `find` returns the first element satisfying
161+
the specified predicate. Because we might not find a matching element, `find`
162+
returns an `Option` rather than the element itself.
162163

163164
Another important consumer is `fold`. Here's what it looks like:
164165

0 commit comments

Comments
 (0)