Skip to content

Commit 5ec3aba

Browse files
committed
Improve documentation for each.
Add description of arguments, and an example.
1 parent 09bb07b commit 5ec3aba

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
@@ -1170,9 +1170,41 @@ pub pure fn reversed<T: Copy>(v: &[const T]) -> ~[T] {
11701170
}
11711171

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

0 commit comments

Comments
 (0)