Skip to content

Commit 6a21f22

Browse files
committed
update the iterator tutorial
1 parent af9ddd7 commit 6a21f22

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

doc/tutorial-container.md

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,10 @@ iterator object. For example, vector slices several iterators available:
112112
113113
* `iter()` and `rev_iter()`, for immutable references to the elements
114114
* `mut_iter()` and `mut_rev_iter()`, for mutable references to the elements
115-
* `consume_iter()` and `consume_rev_iter`, to move the elements out by-value
115+
* `move_iter()` and `move_rev_iter`, to move the elements out by-value
116116
117117
A typical mutable container will implement at least `iter()`, `mut_iter()` and
118-
`consume_iter()` along with the reverse variants if it maintains an order.
118+
`move_iter()` along with the reverse variants if it maintains an order.
119119
120120
### Freezing
121121
@@ -139,9 +139,9 @@ and `&mut`.
139139
140140
## Iterator adaptors
141141
142-
The `IteratorUtil` trait implements common algorithms as methods extending
143-
every `Iterator` implementation. For example, the `fold` method will accumulate
144-
the items yielded by an `Iterator` into a single value:
142+
The `Iterator` trait provides many common algorithms as default methods. For
143+
example, the `fold` method will accumulate the items yielded by an `Iterator`
144+
into a single value:
145145
146146
~~~
147147
let xs = [1, 9, 2, 3, 14, 12];
@@ -154,14 +154,10 @@ Some adaptors return an adaptor object implementing the `Iterator` trait itself:
154154
~~~
155155
let xs = [1, 9, 2, 3, 14, 12];
156156
let ys = [5, 2, 1, 8];
157-
let sum = xs.iter().chain_(ys.iter()).fold(0, |a, b| a + *b);
157+
let sum = xs.iter().chain(ys.iter()).fold(0, |a, b| a + *b);
158158
assert_eq!(sum, 57);
159159
~~~
160160
161-
Note that some adaptors like the `chain_` method above use a trailing
162-
underscore to work around an issue with method resolve. The underscores will be
163-
dropped when they become unnecessary.
164-
165161
## For loops
166162
167163
The `for` keyword can be used as sugar for iterating through any iterator:
@@ -212,7 +208,7 @@ Iterators offer generic conversion to containers with the `collect` adaptor:
212208
213209
~~~
214210
let xs = [0, 1, 1, 2, 3, 5, 8];
215-
let ys = xs.rev_iter().skip(1).transform(|&x| x * 2).collect::<~[int]>();
211+
let ys = xs.rev_iter().skip(1).map(|&x| x * 2).collect::<~[int]>();
216212
assert_eq!(ys, ~[10, 6, 4, 2, 2, 0]);
217213
~~~
218214
@@ -307,13 +303,13 @@ for &x in it.invert() {
307303
The `rev_iter` and `mut_rev_iter` methods on vectors just return an inverted
308304
version of the standard immutable and mutable vector iterators.
309305
310-
The `chain_`, `transform`, `filter`, `filter_map` and `peek` adaptors are
306+
The `chain`, `map`, `filter`, `filter_map` and `inspect` adaptors are
311307
`DoubleEndedIterator` implementations if the underlying iterators are.
312308
313309
~~~
314310
let xs = [1, 2, 3, 4];
315311
let ys = [5, 6, 7, 8];
316-
let mut it = xs.iter().chain_(ys.iter()).transform(|&x| x * 2);
312+
let mut it = xs.iter().chain(ys.iter()).map(|&x| x * 2);
317313

318314
printfln!("%?", it.next()); // prints `Some(2)`
319315

@@ -329,13 +325,13 @@ The `RandomAccessIterator` trait represents an iterator offering random access
329325
to the whole range. The `indexable` method retrieves the number of elements
330326
accessible with the `idx` method.
331327
332-
The `chain_` adaptor is an implementation of `RandomAccessIterator` if the
328+
The `chain` adaptor is an implementation of `RandomAccessIterator` if the
333329
underlying iterators are.
334330
335331
~~~
336332
let xs = [1, 2, 3, 4, 5];
337333
let ys = ~[7, 9, 11];
338-
let mut it = xs.iter().chain_(ys.iter());
334+
let mut it = xs.iter().chain(ys.iter());
339335
printfln!("%?", it.idx(0)); // prints `Some(&1)`
340336
printfln!("%?", it.idx(5)); // prints `Some(&7)`
341337
printfln!("%?", it.idx(7)); // prints `Some(&11)`

0 commit comments

Comments
 (0)