about summary refs log tree commit diff
path: root/src/libcore
diff options
context:
space:
mode:
authorNiko Matsakis <niko@alum.mit.edu>2012-05-04 12:33:04 -0700
committerNiko Matsakis <niko@alum.mit.edu>2012-05-04 12:33:08 -0700
commit50ec6bd2c3c472ea140ed60de38dd50c672fc80a (patch)
treedd040e82e0eba8038dd06424091b6fc575f720aa /src/libcore
parent8affc78e8a0e420e1755a34fc7f5e4021c512e9d (diff)
downloadrust-50ec6bd2c3c472ea140ed60de38dd50c672fc80a.tar.gz
rust-50ec6bd2c3c472ea140ed60de38dd50c672fc80a.zip
new cap clause syntax
Diffstat (limited to 'src/libcore')
-rw-r--r--src/libcore/vec.rs8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/libcore/vec.rs b/src/libcore/vec.rs
index 3215f3b9f28..cddb1346c01 100644
--- a/src/libcore/vec.rs
+++ b/src/libcore/vec.rs
@@ -1096,6 +1096,14 @@ impl extensions<T> for [T] {
     #[inline]
     fn map<U>(f: fn(T) -> U) -> [U] { map(self, f) }
     #[doc = "
+    Apply a function to the index and value of each element in the vector
+    and return the results
+    "]
+    fn mapi<U>(f: fn(uint, T) -> U) -> [U] {
+        let mut i = 0u;
+        self.map { |e| i += 1u; f(i - 1u, e) }
+    }
+    #[doc = "
     Apply a function to each element of a vector and return a concatenation
     of each result vector
     "]