File tree Expand file tree Collapse file tree 1 file changed +6
-4
lines changed Expand file tree Collapse file tree 1 file changed +6
-4
lines changed Original file line number Diff line number Diff line change @@ -311,10 +311,12 @@ for i in (1..100).filter(|&x| x % 2 == 0) {
311311```
312312
313313This will print all of the even numbers between one and a hundred.
314- (Note that because ` filter ` doesn't consume the elements that are
315- being iterated over, it is passed a reference to each element, and
316- thus the filter predicate uses the ` &x ` pattern to extract the integer
317- itself.)
314+ (Note that, unlike ` map ` , the closure passed to ` filter ` is passed a reference
315+ to the element instead of the element itself. The filter predicate here uses
316+ the ` &x ` pattern to extract the integer. The filter closure is passed a
317+ reference because it returns ` true ` or ` false ` instead of the element,
318+ so the ` filter ` implementation must retain ownership to put the elements
319+ into the newly constructed iterator.)
318320
319321You can chain all three things together: start with an iterator, adapt it
320322a few times, and then consume the result. Check it out:
You can’t perform that action at this time.
0 commit comments