Skip to content

Commit aec0b51

Browse files
committed
Added a few more extension methods on vectors, and fixed a pretty printer bug.
1 parent 9fa4763 commit aec0b51

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

src/libcore/vec.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,16 @@ fn all<T>(v: [T], f: fn(T) -> bool) -> bool {
580580
ret true;
581581
}
582582

583+
#[doc = "
584+
Return true if a predicate matches all elements
585+
586+
If the vector contains no elements then true is returned.
587+
"]
588+
fn alli<T>(v: [T], f: fn(uint, T) -> bool) -> bool {
589+
for eachi(v) {|i, elem| if !f(i, elem) { ret false; } }
590+
ret true;
591+
}
592+
583593
#[doc = "
584594
Return true if a predicate matches all elements in both vectors.
585595
@@ -1107,6 +1117,12 @@ impl extensions<T> for [T] {
11071117
let mut i = 0u;
11081118
self.map { |e| i += 1u; f(i - 1u, e) }
11091119
}
1120+
#[doc = "Returns true if the function returns true for all elements.
1121+
1122+
If the vector is empty, true is returned."]
1123+
fn alli(f: fn(uint, T) -> bool) -> bool {
1124+
alli(self, f)
1125+
}
11101126
#[doc = "
11111127
Apply a function to each element of a vector and return a concatenation
11121128
of each result vector

src/librustsyntax/print/pprust.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,10 @@ fn print_region(s: ps, region: @ast::region) {
337337
}
338338

339339
fn print_type(s: ps, &&ty: @ast::ty) {
340+
print_type_ex(s, ty, false);
341+
}
342+
343+
fn print_type_ex(s: ps, &&ty: @ast::ty, print_colons: bool) {
340344
maybe_print_comment(s, ty.span.lo);
341345
ibox(s, 0u);
342346
alt ty.node {
@@ -384,7 +388,7 @@ fn print_type(s: ps, &&ty: @ast::ty) {
384388
ast::ty_fn(proto, d) {
385389
print_ty_fn(s, some(proto), d, none, none);
386390
}
387-
ast::ty_path(path, _) { print_path(s, path, false); }
391+
ast::ty_path(path, _) { print_path(s, path, print_colons); }
388392
ast::ty_constr(t, cs) {
389393
print_type(s, t);
390394
space(s.s);
@@ -961,7 +965,7 @@ fn print_expr(s: ps, &&expr: @ast::expr) {
961965
print_op_maybe_parens(s, expr, parse::prec::as_prec);
962966
space(s.s);
963967
word_space(s, "as");
964-
print_type(s, ty);
968+
print_type_ex(s, ty, true);
965969
}
966970
ast::expr_if(test, blk, elseopt) {
967971
print_if(s, test, blk, elseopt, false);

0 commit comments

Comments
 (0)