diff options
| author | Eric Holk <eric.holk@gmail.com> | 2012-05-15 14:51:33 -0700 | 
|---|---|---|
| committer | Eric Holk <eric.holk@gmail.com> | 2012-05-17 12:00:24 -0700 | 
| commit | aec0b51d9cca576b38023c4f8a11f28452ea8d55 (patch) | |
| tree | 357d27b5623c3f0899681c3c840542d0f02f3be9 | |
| parent | 9fa4763604b8d9bd342d5ead58442ef1b3643b5a (diff) | |
| download | rust-aec0b51d9cca576b38023c4f8a11f28452ea8d55.tar.gz rust-aec0b51d9cca576b38023c4f8a11f28452ea8d55.zip  | |
Added a few more extension methods on vectors, and fixed a pretty printer bug.
| -rw-r--r-- | src/libcore/vec.rs | 16 | ||||
| -rw-r--r-- | src/librustsyntax/print/pprust.rs | 8 | 
2 files changed, 22 insertions, 2 deletions
diff --git a/src/libcore/vec.rs b/src/libcore/vec.rs index d083bcae679..3c6a3d9f7b2 100644 --- a/src/libcore/vec.rs +++ b/src/libcore/vec.rs @@ -581,6 +581,16 @@ fn all<T>(v: [T], f: fn(T) -> bool) -> bool { } #[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. If the vectors are not the same size then false is returned. @@ -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 diff --git a/src/librustsyntax/print/pprust.rs b/src/librustsyntax/print/pprust.rs index 70e3ec33c62..cc541cc4f4d 100644 --- a/src/librustsyntax/print/pprust.rs +++ b/src/librustsyntax/print/pprust.rs @@ -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);  | 
