Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 34 additions & 2 deletions src/libcore/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1170,9 +1170,41 @@ pub pure fn reversed<T: Copy>(v: &[const T]) -> ~[T] {
}

/**
* Iterates over a vector, with option to break
* Iterates over a vector, yielding each element to a closure.
*
* Return true to continue, false to break.
* # Arguments
*
* * `v` - A vector, to be iterated over
* * `f` - A closure to do the iterating. Within this closure, return true to continue iterating, false to break.
*
* # Examples
* ~~~
* [1,2,3].each(|&i| {
* io::println(int::str(i));
* true
* });
* ~~~
*
* ~~~
* [1,2,3,4,5].each(|&i| {
* if i < 4 {
* io::println(int::str(i));
* true
* }
* else {
* false
* }
* });
* ~~~
*
* You probably will want to use each with a `for`/`do` expression, depending
* on your iteration needs:
*
* ~~~
* for [1,2,3].each |&i| {
* io::println(int::str(i));
* }
* ~~~
*/
#[inline(always)]
pub pure fn each<T>(v: &r/[T], f: fn(&r/T) -> bool) {
Expand Down