core: Add iter::reverse
This commit is contained in:
parent
c21db3bbc2
commit
85175d639f
1 changed files with 10 additions and 0 deletions
|
@ -77,6 +77,11 @@ fn to_list<A:copy,IA:iterable<A>>(self: IA) -> [A] {
|
|||
foldl::<A,[A],IA>(self, [], {|r, a| r + [a]})
|
||||
}
|
||||
|
||||
// FIXME: This could be made more efficient with an riterable interface
|
||||
fn reverse<A:copy,IA:iterable<A>>(self: IA, blk: fn(A)) {
|
||||
vec::riter(to_list(self), blk)
|
||||
}
|
||||
|
||||
fn repeat(times: uint, blk: fn()) {
|
||||
let i = 0u;
|
||||
while i < times {
|
||||
|
@ -214,3 +219,8 @@ fn test_max() {
|
|||
fn test_max_empty() {
|
||||
max::<int, [int]>([]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_reverse() {
|
||||
assert to_list(bind reverse([1, 2, 3], _)) == [3, 2, 1];
|
||||
}
|
Loading…
Reference in a new issue