From ded2370a740e7d3b3bd631012f1a724c11b315cf Mon Sep 17 00:00:00 2001 From: David Elliott Date: Sat, 26 Sep 2015 10:36:37 -0700 Subject: [PATCH] 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!" --- src/doc/trpl/iterators.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/doc/trpl/iterators.md b/src/doc/trpl/iterators.md index 1c574f02091..b52e0fefa57 100644 --- a/src/doc/trpl/iterators.md +++ b/src/doc/trpl/iterators.md @@ -150,15 +150,16 @@ let greater_than_forty_two = (0..100) .find(|x| *x > 42); match greater_than_forty_two { - Some(_) => println!("We got some numbers!"), - None => println!("No numbers found :("), + Some(_) => println!("Found a match!"), + None => println!("No match found :("), } ``` `find` takes a closure, and works on a reference to each element of an iterator. This closure returns `true` if the element is the element we're -looking for, and `false` otherwise. Because we might not find a matching -element, `find` returns an `Option` rather than the element itself. +looking for, and `false` otherwise. `find` returns the first element satisfying +the specified predicate. Because we might not find a matching element, `find` +returns an `Option` rather than the element itself. Another important consumer is `fold`. Here's what it looks like: