From 85175d639f0b40062d2741f4918df48aee3ef758 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Sun, 12 Feb 2012 02:44:40 -0800 Subject: [PATCH] core: Add iter::reverse --- src/libcore/iter.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs index 23779e04487..8500ce7a783 100644 --- a/src/libcore/iter.rs +++ b/src/libcore/iter.rs @@ -77,6 +77,11 @@ fn to_list>(self: IA) -> [A] { foldl::(self, [], {|r, a| r + [a]}) } +// FIXME: This could be made more efficient with an riterable interface +fn reverse>(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::([]); } + +#[test] +fn test_reverse() { + assert to_list(bind reverse([1, 2, 3], _)) == [3, 2, 1]; +} \ No newline at end of file