Added a few more extension methods on vectors, and fixed a pretty printer bug.
This commit is contained in:
parent
9fa4763604
commit
aec0b51d9c
@ -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
|
||||
|
@ -337,6 +337,10 @@ fn print_region(s: ps, region: @ast::region) {
|
||||
}
|
||||
|
||||
fn print_type(s: ps, &&ty: @ast::ty) {
|
||||
print_type_ex(s, ty, false);
|
||||
}
|
||||
|
||||
fn print_type_ex(s: ps, &&ty: @ast::ty, print_colons: bool) {
|
||||
maybe_print_comment(s, ty.span.lo);
|
||||
ibox(s, 0u);
|
||||
alt ty.node {
|
||||
@ -384,7 +388,7 @@ fn print_type(s: ps, &&ty: @ast::ty) {
|
||||
ast::ty_fn(proto, d) {
|
||||
print_ty_fn(s, some(proto), d, none, none);
|
||||
}
|
||||
ast::ty_path(path, _) { print_path(s, path, false); }
|
||||
ast::ty_path(path, _) { print_path(s, path, print_colons); }
|
||||
ast::ty_constr(t, cs) {
|
||||
print_type(s, t);
|
||||
space(s.s);
|
||||
@ -961,7 +965,7 @@ fn print_expr(s: ps, &&expr: @ast::expr) {
|
||||
print_op_maybe_parens(s, expr, parse::prec::as_prec);
|
||||
space(s.s);
|
||||
word_space(s, "as");
|
||||
print_type(s, ty);
|
||||
print_type_ex(s, ty, true);
|
||||
}
|
||||
ast::expr_if(test, blk, elseopt) {
|
||||
print_if(s, test, blk, elseopt, false);
|
||||
|
Loading…
Reference in New Issue
Block a user