Skip to content

Commit 6dece91

Browse files
committed
stdlib: Add vec::eachi to the standard library
1 parent c04efec commit 6dece91

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/lib/vec.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,16 @@ fn enum_uints(start: uint, end: uint) : uint::le(start, end) -> [uint] {
332332
ret r;
333333
}
334334

335+
fn eachi<@T>(f: block(T, uint) -> (), v: [mutable? T]) {
336+
let i = 0u;
337+
let l = len(v);
338+
while (i < l) {
339+
let elem = v[i]; // Satisfy alias checker
340+
f(elem, i);
341+
i += 1u;
342+
}
343+
}
344+
335345
// Iterate over a list with with the indexes
336346
iter iter2<@T>(v: [T]) -> (uint, T) {
337347
let i = 0u;

0 commit comments

Comments
 (0)