1
Fork 0

core: rename vec.filter to vec.filtered

This commit is contained in:
Erick Tryzelaar 2013-01-07 21:15:25 -08:00
parent 9a7e261562
commit 2891a49f0d
12 changed files with 27 additions and 25 deletions

View file

@ -526,7 +526,7 @@ fn make_run_args(config: config, _props: test_props, testfile: &Path) ->
fn split_maybe_args(argstr: Option<~str>) -> ~[~str] { fn split_maybe_args(argstr: Option<~str>) -> ~[~str] {
fn rm_whitespace(v: ~[~str]) -> ~[~str] { fn rm_whitespace(v: ~[~str]) -> ~[~str] {
vec::filter(v, |s| !str::is_whitespace(*s)) v.filtered(|s| !str::is_whitespace(*s))
} }
match argstr { match argstr {

View file

@ -619,7 +619,7 @@ pub fn list_dir(p: &Path) -> ~[~str] {
#[cfg(windows)] #[cfg(windows)]
fn star(p: &Path) -> Path { p.push("*") } fn star(p: &Path) -> Path { p.push("*") }
do rustrt::rust_list_files2(star(p).to_str()).filter |filename| { do rustrt::rust_list_files2(star(p).to_str()).filtered |filename| {
*filename != ~"." && *filename != ~".." *filename != ~"." && *filename != ~".."
} }
} }

View file

@ -853,7 +853,7 @@ pub pure fn filter_map<T, U: Copy>(v: &[T], f: fn(t: &T) -> Option<U>)
* Apply function `f` to each element of `v` and return a vector containing * Apply function `f` to each element of `v` and return a vector containing
* only those elements for which `f` returned true. * only those elements for which `f` returned true.
*/ */
pub pure fn filter<T: Copy>(v: &[T], f: fn(t: &T) -> bool) -> ~[T] { pub pure fn filtered<T: Copy>(v: &[T], f: fn(t: &T) -> bool) -> ~[T] {
let mut result = ~[]; let mut result = ~[];
for each(v) |elem| { for each(v) |elem| {
if f(elem) { unsafe { result.push(*elem); } } if f(elem) { unsafe { result.push(*elem); } }
@ -1752,7 +1752,7 @@ impl<T: Eq> &[T]: ImmutableEqVector<T> {
} }
pub trait ImmutableCopyableVector<T> { pub trait ImmutableCopyableVector<T> {
pure fn filter(&self, f: fn(t: &T) -> bool) -> ~[T]; pure fn filtered(&self, f: fn(&T) -> bool) -> ~[T];
pure fn rfind(&self, f: fn(t: &T) -> bool) -> Option<T>; pure fn rfind(&self, f: fn(t: &T) -> bool) -> Option<T>;
pure fn partitioned(&self, f: fn(&T) -> bool) -> (~[T], ~[T]); pure fn partitioned(&self, f: fn(&T) -> bool) -> (~[T], ~[T]);
} }
@ -1767,8 +1767,8 @@ impl<T: Copy> &[T]: ImmutableCopyableVector<T> {
* containing only those elements for which `f` returned true. * containing only those elements for which `f` returned true.
*/ */
#[inline] #[inline]
pure fn filter(&self, f: fn(t: &T) -> bool) -> ~[T] { pure fn filtered(&self, f: fn(t: &T) -> bool) -> ~[T] {
filter(*self, f) filtered(*self, f)
} }
/** /**
@ -3618,7 +3618,7 @@ mod tests {
fn test_filter_fail() { fn test_filter_fail() {
let v = [(~0, @0), (~0, @0), (~0, @0), (~0, @0)]; let v = [(~0, @0), (~0, @0), (~0, @0), (~0, @0)];
let mut i = 0; let mut i = 0;
do filter(v) |_elt| { do v.filtered |_elt| {
if i == 2 { if i == 2 {
fail fail
} }

View file

@ -262,8 +262,9 @@ fn as_str(f: fn@(+x: io::Writer)) -> ~str {
fn check_variants_of_ast(crate: ast::crate, codemap: @codemap::CodeMap, fn check_variants_of_ast(crate: ast::crate, codemap: @codemap::CodeMap,
filename: &Path, cx: context) { filename: &Path, cx: context) {
let stolen = steal(crate, cx.mode); let stolen = steal(crate, cx.mode);
let extra_exprs = vec::filter(common_exprs(), let extra_exprs = do common_exprs().filtered |a| {
|a| safe_to_use_expr(*a, cx.mode) ); safe_to_use_expr(*a, cx.mode)
};
check_variants_T(crate, codemap, filename, ~"expr", check_variants_T(crate, codemap, filename, ~"expr",
extra_exprs + stolen.exprs, pprust::expr_to_str, extra_exprs + stolen.exprs, pprust::expr_to_str,
replace_expr_in_crate, cx); replace_expr_in_crate, cx);

View file

@ -103,11 +103,11 @@ fn fold_item_underscore(cx: ctxt, +item: ast::item_,
fld: fold::ast_fold) -> ast::item_ { fld: fold::ast_fold) -> ast::item_ {
let item = match item { let item = match item {
ast::item_impl(a, b, c, methods) => { ast::item_impl(a, b, c, methods) => {
let methods = methods.filter(|m| method_in_cfg(cx, *m) ); let methods = methods.filtered(|m| method_in_cfg(cx, *m) );
ast::item_impl(a, b, c, methods) ast::item_impl(a, b, c, methods)
} }
ast::item_trait(ref a, ref b, ref methods) => { ast::item_trait(ref a, ref b, ref methods) => {
let methods = methods.filter(|m| trait_method_in_cfg(cx, m) ); let methods = methods.filtered(|m| trait_method_in_cfg(cx, m) );
ast::item_trait(/*bad*/copy *a, /*bad*/copy *b, methods) ast::item_trait(/*bad*/copy *a, /*bad*/copy *b, methods)
} }
item => item item => item

View file

@ -256,7 +256,7 @@ fn encode_ast(ebml_w: writer::Encoder, item: ast::inlined_item) {
// inlined items. // inlined items.
fn simplify_ast(ii: ast::inlined_item) -> ast::inlined_item { fn simplify_ast(ii: ast::inlined_item) -> ast::inlined_item {
fn drop_nested_items(blk: ast::blk_, fld: fold::ast_fold) -> ast::blk_ { fn drop_nested_items(blk: ast::blk_, fld: fold::ast_fold) -> ast::blk_ {
let stmts_sans_items = do vec::filter(blk.stmts) |stmt| { let stmts_sans_items = do blk.stmts.filtered |stmt| {
match stmt.node { match stmt.node {
ast::stmt_expr(_, _) | ast::stmt_semi(_, _) | ast::stmt_expr(_, _) | ast::stmt_semi(_, _) |
ast::stmt_decl(@ast::spanned { node: ast::decl_local(_), ast::stmt_decl(@ast::spanned { node: ast::decl_local(_),

View file

@ -174,7 +174,7 @@ fn trans_log(log_ex: @ast::expr,
let modpath = vec::append( let modpath = vec::append(
~[path_mod(ccx.sess.ident_of(/*bad*/copy ccx.link_meta.name))], ~[path_mod(ccx.sess.ident_of(/*bad*/copy ccx.link_meta.name))],
vec::filter(bcx.fcx.path, |e| bcx.fcx.path.filtered(|e|
match *e { path_mod(_) => true, _ => false } match *e { path_mod(_) => true, _ => false }
)); ));
// XXX: Bad copy. // XXX: Bad copy.

View file

@ -129,7 +129,7 @@ fn fold_mod(
fn strip_mod(doc: doc::ModDoc) -> doc::ModDoc { fn strip_mod(doc: doc::ModDoc) -> doc::ModDoc {
doc::ModDoc_({ doc::ModDoc_({
items: do vec::filter(doc.items) |item| { items: do doc.items.filtered |item| {
match *item { match *item {
doc::ModTag(_) => false, doc::ModTag(_) => false,
doc::NmodTag(_) => false, doc::NmodTag(_) => false,

View file

@ -43,9 +43,9 @@ fn fold_mod(
let doc = fold::default_any_fold_mod(fold, doc); let doc = fold::default_any_fold_mod(fold, doc);
doc::ModDoc_({ doc::ModDoc_({
items: vec::filter(doc.items, |ItemTag| { items: do doc.items.filtered |ItemTag| {
!is_hidden(fold.ctxt, ItemTag.item()) !is_hidden(fold.ctxt, ItemTag.item())
}), },
.. *doc .. *doc
}) })
} }

View file

@ -49,9 +49,9 @@ fn fold_mod(
let doc = fold::default_any_fold_mod(fold, doc); let doc = fold::default_any_fold_mod(fold, doc);
doc::ModDoc_({ doc::ModDoc_({
items: do doc.items.filter |ItemTag| { items: doc.items.filter(|ItemTag| {
is_visible(fold.ctxt, ItemTag.item()) is_visible(fold.ctxt, ItemTag.item())
}, }),
.. *doc .. *doc
}) })
} }

View file

@ -316,11 +316,12 @@ pure fn unguarded_pat(a: &arm) -> Option<~[@pat]> {
} }
fn public_methods(ms: ~[@method]) -> ~[@method] { fn public_methods(ms: ~[@method]) -> ~[@method] {
vec::filter(ms, do ms.filtered |m| {
|m| match m.vis { match m.vis {
public => true, public => true,
_ => false _ => false
}) }
}
} }
// extract a ty_method from a trait_method. if the trait_method is // extract a ty_method from a trait_method. if the trait_method is

View file

@ -121,7 +121,7 @@ fn expand_auto_encode(
} }
fn filter_attrs(item: @ast::item) -> @ast::item { fn filter_attrs(item: @ast::item) -> @ast::item {
@{attrs: vec::filter(item.attrs, |a| !is_auto_encode(a)), @{attrs: item.attrs.filtered(|a| !is_auto_encode(a)),
.. *item} .. *item}
} }
@ -185,7 +185,7 @@ fn expand_auto_decode(
} }
fn filter_attrs(item: @ast::item) -> @ast::item { fn filter_attrs(item: @ast::item) -> @ast::item {
@{attrs: vec::filter(item.attrs, |a| !is_auto_decode(a)), @{attrs: item.attrs.filtered(|a| !is_auto_decode(a)),
.. *item} .. *item}
} }