Added a few more extension methods on vectors, and fixed a pretty printer bug.
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user