stdlib: Add vec::eachi to the standard library

This commit is contained in:
Patrick Walton 2011-09-29 17:31:11 -07:00
parent c04efec87f
commit 6dece91ed3
1 changed files with 10 additions and 0 deletions

View File

@ -332,6 +332,16 @@ fn enum_uints(start: uint, end: uint) : uint::le(start, end) -> [uint] {
ret r;
}
fn eachi<@T>(f: block(T, uint) -> (), v: [mutable? T]) {
let i = 0u;
let l = len(v);
while (i < l) {
let elem = v[i]; // Satisfy alias checker
f(elem, i);
i += 1u;
}
}
// Iterate over a list with with the indexes
iter iter2<@T>(v: [T]) -> (uint, T) {
let i = 0u;