about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDaniel Micay <danielmicay@gmail.com>2013-07-23 14:37:06 -0400
committerDaniel Micay <danielmicay@gmail.com>2013-07-24 09:45:20 -0400
commit8c0227251299982eaab1c8ebebc76bd856efd38f (patch)
tree1abfd6c8946425740a2ec5a82c909257c7e23d12
parent626bb5a86674c57c589602c858b5bc7412b7dd64 (diff)
downloadrust-8c0227251299982eaab1c8ebebc76bd856efd38f.tar.gz
rust-8c0227251299982eaab1c8ebebc76bd856efd38f.zip
expand on double-ended iterators in the tutorial
-rw-r--r--doc/tutorial-container.md28
1 files changed, 22 insertions, 6 deletions
diff --git a/doc/tutorial-container.md b/doc/tutorial-container.md
index 2146b76a4af..ada55de805f 100644
--- a/doc/tutorial-container.md
+++ b/doc/tutorial-container.md
@@ -192,7 +192,7 @@ let mut it = xs.iter().zip(ys.iter());
 
 // print out the pairs of elements up to (&3, &"baz")
 for it.advance |(x, y)| {
-    println(fmt!("%d %s", *x, *y));
+    printfln!("%d %s", *x, *y);
 
     if *x == 3 {
         break;
@@ -200,7 +200,7 @@ for it.advance |(x, y)| {
 }
 
 // yield and print the last pair from the iterator
-println(fmt!("last: %?", it.next()));
+printfln!("last: %?", it.next());
 
 // the iterator is now fully consumed
 assert!(it.next().is_none());
@@ -294,15 +294,31 @@ another `DoubleEndedIterator` with `next` and `next_back` exchanged.
 ~~~
 let xs = [1, 2, 3, 4, 5, 6];
 let mut it = xs.iter();
-println(fmt!("%?", it.next())); // prints `Some(&1)`
-println(fmt!("%?", it.next())); // prints `Some(&2)`
-println(fmt!("%?", it.next_back())); // prints `Some(&6)`
+printfln!("%?", it.next()); // prints `Some(&1)`
+printfln!("%?", it.next()); // prints `Some(&2)`
+printfln!("%?", it.next_back()); // prints `Some(&6)`
 
 // prints `5`, `4` and `3`
 for it.invert().advance |&x| {
-    println(fmt!("%?", x))
+    printfln!("%?", x)
 }
 ~~~
 
 The `rev_iter` and `mut_rev_iter` methods on vectors just return an inverted
 version of the standard immutable and mutable vector iterators.
+
+The `chain_`, `transform`, `filter`, `filter_map` and `peek` adaptors are
+`DoubleEndedIterator` implementations if the underlying iterators are.
+
+~~~
+let xs = [1, 2, 3, 4];
+let ys = [5, 6, 7, 8];
+let mut it = xs.iter().chain_(ys.iter()).transform(|&x| x * 2);
+
+printfln!("%?", it.next()); // prints `Some(2)`
+
+// prints `16`, `14`, `12`, `10`, `8`, `6`, `4`
+for it.invert().advance |x| {
+    printfln!("%?", x);
+}
+~~~