Added a few more extension methods on vectors, and fixed a pretty printer bug.

This commit is contained in:
Eric Holk
2012-05-15 14:51:33 -07:00
parent 9fa4763604
commit aec0b51d9c
2 changed files with 22 additions and 2 deletions

View File

@@ -580,6 +580,16 @@ fn all<T>(v: [T], f: fn(T) -> bool) -> bool {
ret true;
}
#[doc = "
Return true if a predicate matches all elements
If the vector contains no elements then true is returned.
"]
fn alli<T>(v: [T], f: fn(uint, T) -> bool) -> bool {
for eachi(v) {|i, elem| if !f(i, elem) { ret false; } }
ret true;
}
#[doc = "
Return true if a predicate matches all elements in both vectors.
@@ -1107,6 +1117,12 @@ impl extensions<T> for [T] {
let mut i = 0u;
self.map { |e| i += 1u; f(i - 1u, e) }
}
#[doc = "Returns true if the function returns true for all elements.
If the vector is empty, true is returned."]
fn alli(f: fn(uint, T) -> bool) -> bool {
alli(self, f)
}
#[doc = "
Apply a function to each element of a vector and return a concatenation
of each result vector