Skip to content

Commit 7af1080

Browse files
committed
Merge pull request #4308 from steveklabnik/patch-1
Improve documentation for each.
2 parents 2d7b96a + 5ec3aba commit 7af1080

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

src/libcore/vec.rs

+34-2
Original file line numberDiff line numberDiff line change
@@ -1177,9 +1177,41 @@ pub pure fn reversed<T: Copy>(v: &[const T]) -> ~[T] {
11771177
}
11781178

11791179
/**
1180-
* Iterates over a vector, with option to break
1180+
* Iterates over a vector, yielding each element to a closure.
11811181
*
1182-
* Return true to continue, false to break.
1182+
* # Arguments
1183+
*
1184+
* * `v` - A vector, to be iterated over
1185+
* * `f` - A closure to do the iterating. Within this closure, return true to continue iterating, false to break.
1186+
*
1187+
* # Examples
1188+
* ~~~
1189+
* [1,2,3].each(|&i| {
1190+
* io::println(int::str(i));
1191+
* true
1192+
* });
1193+
* ~~~
1194+
*
1195+
* ~~~
1196+
* [1,2,3,4,5].each(|&i| {
1197+
* if i < 4 {
1198+
* io::println(int::str(i));
1199+
* true
1200+
* }
1201+
* else {
1202+
* false
1203+
* }
1204+
* });
1205+
* ~~~
1206+
*
1207+
* You probably will want to use each with a `for`/`do` expression, depending
1208+
* on your iteration needs:
1209+
*
1210+
* ~~~
1211+
* for [1,2,3].each |&i| {
1212+
* io::println(int::str(i));
1213+
* }
1214+
* ~~~
11831215
*/
11841216
#[inline(always)]
11851217
pub pure fn each<T>(v: &r/[T], f: fn(&r/T) -> bool) {

0 commit comments

Comments
 (0)