Remove vec::{filter, filtered, filter_map, filter_mapped}, replaced by iterators.
This commit is contained in:
parent
eee6775642
commit
de0d696561
@ -523,7 +523,7 @@ pub fn filter_tests(
|
|||||||
} else { return option::None; }
|
} else { return option::None; }
|
||||||
}
|
}
|
||||||
|
|
||||||
vec::filter_map(filtered, |x| filter_fn(x, filter_str))
|
filtered.consume_iter().filter_map(|x| filter_fn(x, filter_str)).collect()
|
||||||
};
|
};
|
||||||
|
|
||||||
// Maybe pull out the ignored test and unignore them
|
// Maybe pull out the ignored test and unignore them
|
||||||
@ -541,7 +541,7 @@ pub fn filter_tests(
|
|||||||
None
|
None
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
vec::filter_map(filtered, |x| filter(x))
|
filtered.consume_iter().filter_map(|x| filter(x)).collect()
|
||||||
};
|
};
|
||||||
|
|
||||||
// Sort the tests alphabetically
|
// Sort the tests alphabetically
|
||||||
@ -720,9 +720,9 @@ impl BenchHarness {
|
|||||||
// Eliminate outliers
|
// Eliminate outliers
|
||||||
let med = samples.median();
|
let med = samples.median();
|
||||||
let mad = samples.median_abs_dev();
|
let mad = samples.median_abs_dev();
|
||||||
let samples = do vec::filter(samples) |f| {
|
let samples = do samples.consume_iter().filter |f| {
|
||||||
num::abs(*f - med) <= 3.0 * mad
|
num::abs(*f - med) <= 3.0 * mad
|
||||||
};
|
}.collect::<~[f64]>();
|
||||||
|
|
||||||
debug!("%u samples, median %f, MAD=%f, %u survived filter",
|
debug!("%u samples, median %f, MAD=%f, %u survived filter",
|
||||||
n_samples, med as float, mad as float,
|
n_samples, med as float, mad as float,
|
||||||
|
@ -10,7 +10,6 @@
|
|||||||
|
|
||||||
|
|
||||||
use std::option;
|
use std::option;
|
||||||
use std::vec;
|
|
||||||
use syntax::{ast, fold, attr};
|
use syntax::{ast, fold, attr};
|
||||||
|
|
||||||
type in_cfg_pred = @fn(attrs: ~[ast::attribute]) -> bool;
|
type in_cfg_pred = @fn(attrs: ~[ast::attribute]) -> bool;
|
||||||
@ -61,13 +60,15 @@ fn filter_view_item(cx: @Context, view_item: @ast::view_item
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn fold_mod(cx: @Context, m: &ast::_mod, fld: @fold::ast_fold) -> ast::_mod {
|
fn fold_mod(cx: @Context, m: &ast::_mod, fld: @fold::ast_fold) -> ast::_mod {
|
||||||
let filtered_items =
|
let filtered_items = do m.items.iter().filter_map |a| {
|
||||||
m.items.filter_mapped(|a| filter_item(cx, *a));
|
filter_item(cx, *a).chain(|x| fld.fold_item(x))
|
||||||
let filtered_view_items =
|
}.collect();
|
||||||
m.view_items.filter_mapped(|a| filter_view_item(cx, *a));
|
let filtered_view_items = do m.view_items.iter().filter_map |a| {
|
||||||
|
filter_view_item(cx, *a).map(|x| fld.fold_view_item(*x))
|
||||||
|
}.collect();
|
||||||
ast::_mod {
|
ast::_mod {
|
||||||
view_items: filtered_view_items.map(|x| fld.fold_view_item(*x)),
|
view_items: filtered_view_items,
|
||||||
items: vec::filter_map(filtered_items, |x| fld.fold_item(x))
|
items: filtered_items
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,14 +84,14 @@ fn fold_foreign_mod(
|
|||||||
nm: &ast::foreign_mod,
|
nm: &ast::foreign_mod,
|
||||||
fld: @fold::ast_fold
|
fld: @fold::ast_fold
|
||||||
) -> ast::foreign_mod {
|
) -> ast::foreign_mod {
|
||||||
let filtered_items =
|
let filtered_items = nm.items.iter().filter_map(|a| filter_foreign_item(cx, *a)).collect();
|
||||||
nm.items.filter_mapped(|a| filter_foreign_item(cx, *a));
|
let filtered_view_items = do nm.view_items.iter().filter_map |a| {
|
||||||
let filtered_view_items =
|
filter_view_item(cx, *a).map(|x| fld.fold_view_item(*x))
|
||||||
nm.view_items.filter_mapped(|a| filter_view_item(cx, *a));
|
}.collect();
|
||||||
ast::foreign_mod {
|
ast::foreign_mod {
|
||||||
sort: nm.sort,
|
sort: nm.sort,
|
||||||
abis: nm.abis,
|
abis: nm.abis,
|
||||||
view_items: filtered_view_items.iter().transform(|x| fld.fold_view_item(*x)).collect(),
|
view_items: filtered_view_items,
|
||||||
items: filtered_items
|
items: filtered_items
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -99,11 +100,13 @@ fn fold_item_underscore(cx: @Context, 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(ref a, b, c, ref methods) => {
|
ast::item_impl(ref a, b, c, ref methods) => {
|
||||||
let methods = methods.filtered(|m| method_in_cfg(cx, *m) );
|
let methods = methods.iter().filter(|m| method_in_cfg(cx, **m))
|
||||||
|
.transform(|x| *x).collect();
|
||||||
ast::item_impl(/*bad*/ copy *a, b, c, methods)
|
ast::item_impl(/*bad*/ copy *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.filtered(|m| trait_method_in_cfg(cx, m) );
|
let methods = methods.iter().filter(|m| trait_method_in_cfg(cx, *m) )
|
||||||
|
.transform(|x| /* bad */copy *x).collect();
|
||||||
ast::item_trait(/*bad*/copy *a, /*bad*/copy *b, methods)
|
ast::item_trait(/*bad*/copy *a, /*bad*/copy *b, methods)
|
||||||
}
|
}
|
||||||
ref item => /*bad*/ copy *item
|
ref item => /*bad*/ copy *item
|
||||||
@ -134,19 +137,12 @@ fn fold_block(
|
|||||||
b: &ast::blk_,
|
b: &ast::blk_,
|
||||||
fld: @fold::ast_fold
|
fld: @fold::ast_fold
|
||||||
) -> ast::blk_ {
|
) -> ast::blk_ {
|
||||||
let filtered_stmts =
|
let resulting_stmts = do b.stmts.iter().filter_map |a| {
|
||||||
b.stmts.filter_mapped(|a| filter_stmt(cx, *a));
|
filter_stmt(cx, *a).chain(|stmt| fld.fold_stmt(stmt))
|
||||||
let filtered_view_items =
|
}.collect();
|
||||||
b.view_items.filter_mapped(|a| filter_view_item(cx, *a));
|
let filtered_view_items = do b.view_items.iter().filter_map |a| {
|
||||||
let filtered_view_items =
|
filter_view_item(cx, *a).map(|x| fld.fold_view_item(*x))
|
||||||
filtered_view_items.map(|x| fld.fold_view_item(*x));
|
}.collect();
|
||||||
let mut resulting_stmts = ~[];
|
|
||||||
for filtered_stmts.iter().advance |stmt| {
|
|
||||||
match fld.fold_stmt(*stmt) {
|
|
||||||
None => {}
|
|
||||||
Some(stmt) => resulting_stmts.push(stmt),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ast::blk_ {
|
ast::blk_ {
|
||||||
view_items: filtered_view_items,
|
view_items: filtered_view_items,
|
||||||
stmts: resulting_stmts,
|
stmts: resulting_stmts,
|
||||||
@ -193,7 +189,9 @@ pub fn metas_in_cfg(cfg: &[@ast::meta_item],
|
|||||||
// Pull the inner meta_items from the #[cfg(meta_item, ...)] attributes,
|
// Pull the inner meta_items from the #[cfg(meta_item, ...)] attributes,
|
||||||
// so we can match against them. This is the list of configurations for
|
// so we can match against them. This is the list of configurations for
|
||||||
// which the item is valid
|
// which the item is valid
|
||||||
let cfg_metas = vec::filter_map(cfg_metas, |i| attr::get_meta_item_list(i));
|
let cfg_metas = cfg_metas.consume_iter()
|
||||||
|
.filter_map(|i| attr::get_meta_item_list(i))
|
||||||
|
.collect::<~[~[@ast::meta_item]]>();
|
||||||
|
|
||||||
if cfg_metas.iter().all(|c| c.is_empty()) { return true; }
|
if cfg_metas.iter().all(|c| c.is_empty()) { return true; }
|
||||||
|
|
||||||
|
@ -109,9 +109,11 @@ fn fold_mod(cx: @mut TestCtxt,
|
|||||||
|
|
||||||
fn nomain(cx: @mut TestCtxt, item: @ast::item) -> @ast::item {
|
fn nomain(cx: @mut TestCtxt, item: @ast::item) -> @ast::item {
|
||||||
if !*cx.sess.building_library {
|
if !*cx.sess.building_library {
|
||||||
@ast::item{attrs: item.attrs.filtered(|attr| {
|
@ast::item{
|
||||||
"main" != attr::get_attr_name(attr)
|
attrs: do item.attrs.iter().filter_map |attr| {
|
||||||
}),.. copy *item}
|
if "main" != attr::get_attr_name(attr) {Some(*attr)} else {None}
|
||||||
|
}.collect(),
|
||||||
|
.. copy *item}
|
||||||
} else { item }
|
} else { item }
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -229,10 +231,10 @@ fn is_ignored(cx: @mut TestCtxt, i: @ast::item) -> bool {
|
|||||||
let ignoreattrs = attr::find_attrs_by_name(i.attrs, "ignore");
|
let ignoreattrs = attr::find_attrs_by_name(i.attrs, "ignore");
|
||||||
let ignoreitems = attr::attr_metas(ignoreattrs);
|
let ignoreitems = attr::attr_metas(ignoreattrs);
|
||||||
return if !ignoreitems.is_empty() {
|
return if !ignoreitems.is_empty() {
|
||||||
let cfg_metas =
|
let cfg_metas = ignoreitems.consume_iter()
|
||||||
vec::concat(
|
.filter_map(|i| attr::get_meta_item_list(i))
|
||||||
vec::filter_map(ignoreitems,
|
.collect::<~[~[@ast::meta_item]]>()
|
||||||
|i| attr::get_meta_item_list(i)));
|
.concat_vec();
|
||||||
config::metas_in_cfg(/*bad*/copy cx.crate.node.config, cfg_metas)
|
config::metas_in_cfg(/*bad*/copy cx.crate.node.config, cfg_metas)
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
|
@ -291,16 +291,16 @@ fn encode_ast(ebml_w: &mut 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 blk.stmts.filtered |stmt| {
|
let stmts_sans_items = do blk.stmts.iter().filter_map |stmt| {
|
||||||
match stmt.node {
|
match stmt.node {
|
||||||
ast::stmt_expr(_, _) | ast::stmt_semi(_, _) |
|
ast::stmt_expr(_, _) | ast::stmt_semi(_, _) |
|
||||||
ast::stmt_decl(@codemap::spanned { node: ast::decl_local(_),
|
ast::stmt_decl(@codemap::spanned { node: ast::decl_local(_), span: _}, _)
|
||||||
span: _}, _) => true,
|
=> Some(*stmt),
|
||||||
ast::stmt_decl(@codemap::spanned { node: ast::decl_item(_),
|
ast::stmt_decl(@codemap::spanned { node: ast::decl_item(_), span: _}, _)
|
||||||
span: _}, _) => false,
|
=> None,
|
||||||
ast::stmt_mac(*) => fail!("unexpanded macro in astencode")
|
ast::stmt_mac(*) => fail!("unexpanded macro in astencode")
|
||||||
}
|
}
|
||||||
};
|
}.collect();
|
||||||
let blk_sans_items = ast::blk_ {
|
let blk_sans_items = ast::blk_ {
|
||||||
view_items: ~[], // I don't know if we need the view_items here,
|
view_items: ~[], // I don't know if we need the view_items here,
|
||||||
// but it doesn't break tests!
|
// but it doesn't break tests!
|
||||||
|
@ -95,7 +95,7 @@ pub fn check_expr(cx: @MatchCheckCtxt, ex: @expr, (s, v): ((), visit::vt<()>)) {
|
|||||||
}
|
}
|
||||||
_ => { /* We assume only enum types can be uninhabited */ }
|
_ => { /* We assume only enum types can be uninhabited */ }
|
||||||
}
|
}
|
||||||
let arms = vec::concat(arms.filter_mapped(unguarded_pat));
|
let arms = arms.iter().filter_map(unguarded_pat).collect::<~[~[@pat]]>().concat_vec();
|
||||||
if arms.is_empty() {
|
if arms.is_empty() {
|
||||||
cx.tcx.sess.span_err(ex.span, "non-exhaustive patterns");
|
cx.tcx.sess.span_err(ex.span, "non-exhaustive patterns");
|
||||||
} else {
|
} else {
|
||||||
@ -265,7 +265,7 @@ pub fn is_useful(cx: &MatchCheckCtxt, m: &matrix, v: &[@pat]) -> useful {
|
|||||||
}
|
}
|
||||||
Some(ref ctor) => {
|
Some(ref ctor) => {
|
||||||
match is_useful(cx,
|
match is_useful(cx,
|
||||||
&m.filter_mapped(|r| default(cx, *r)),
|
&m.iter().filter_map(|r| default(cx, *r)).collect::<matrix>(),
|
||||||
v.tail()) {
|
v.tail()) {
|
||||||
useful_ => useful(left_ty, /*bad*/copy *ctor),
|
useful_ => useful(left_ty, /*bad*/copy *ctor),
|
||||||
ref u => (/*bad*/copy *u)
|
ref u => (/*bad*/copy *u)
|
||||||
@ -287,7 +287,7 @@ pub fn is_useful_specialized(cx: &MatchCheckCtxt,
|
|||||||
arity: uint,
|
arity: uint,
|
||||||
lty: ty::t)
|
lty: ty::t)
|
||||||
-> useful {
|
-> useful {
|
||||||
let ms = m.filter_mapped(|r| specialize(cx, *r, &ctor, arity, lty));
|
let ms = m.iter().filter_map(|r| specialize(cx, *r, &ctor, arity, lty)).collect::<matrix>();
|
||||||
let could_be_useful = is_useful(
|
let could_be_useful = is_useful(
|
||||||
cx, &ms, specialize(cx, v, &ctor, arity, lty).get());
|
cx, &ms, specialize(cx, v, &ctor, arity, lty).get());
|
||||||
match could_be_useful {
|
match could_be_useful {
|
||||||
@ -397,14 +397,14 @@ pub fn missing_ctor(cx: &MatchCheckCtxt,
|
|||||||
ty::ty_unboxed_vec(*) | ty::ty_evec(*) => {
|
ty::ty_unboxed_vec(*) | ty::ty_evec(*) => {
|
||||||
|
|
||||||
// Find the lengths and slices of all vector patterns.
|
// Find the lengths and slices of all vector patterns.
|
||||||
let vec_pat_lens = do m.filter_mapped |r| {
|
let vec_pat_lens = do m.iter().filter_map |r| {
|
||||||
match r[0].node {
|
match r[0].node {
|
||||||
pat_vec(ref before, ref slice, ref after) => {
|
pat_vec(ref before, ref slice, ref after) => {
|
||||||
Some((before.len() + after.len(), slice.is_some()))
|
Some((before.len() + after.len(), slice.is_some()))
|
||||||
}
|
}
|
||||||
_ => None
|
_ => None
|
||||||
}
|
}
|
||||||
};
|
}.collect::<~[(uint, bool)]>();
|
||||||
|
|
||||||
// Sort them by length such that for patterns of the same length,
|
// Sort them by length such that for patterns of the same length,
|
||||||
// those with a destructured slice come first.
|
// those with a destructured slice come first.
|
||||||
|
@ -26,7 +26,6 @@ use util::ppaux;
|
|||||||
use middle::trans::type_::Type;
|
use middle::trans::type_::Type;
|
||||||
|
|
||||||
use std::str;
|
use std::str;
|
||||||
use std::vec;
|
|
||||||
use syntax::ast;
|
use syntax::ast;
|
||||||
use syntax::ast::ident;
|
use syntax::ast::ident;
|
||||||
use syntax::ast_map::path_mod;
|
use syntax::ast_map::path_mod;
|
||||||
@ -190,9 +189,13 @@ pub fn trans_log(log_ex: &ast::expr,
|
|||||||
|
|
||||||
let (modpath, modname) = {
|
let (modpath, modname) = {
|
||||||
let path = &mut bcx.fcx.path;
|
let path = &mut bcx.fcx.path;
|
||||||
let modpath = vec::append(
|
let mut modpath = ~[path_mod(ccx.sess.ident_of(ccx.link_meta.name))];
|
||||||
~[path_mod(ccx.sess.ident_of(ccx.link_meta.name))],
|
for path.iter().advance |e| {
|
||||||
path.filtered(|e| match *e { path_mod(_) => true, _ => false }));
|
match *e {
|
||||||
|
path_mod(_) => { modpath.push(*e) }
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
let modname = path_str(ccx.sess, modpath);
|
let modname = path_str(ccx.sess, modpath);
|
||||||
(modpath, modname)
|
(modpath, modname)
|
||||||
};
|
};
|
||||||
|
@ -45,9 +45,9 @@ pub fn parse_crate(attrs: ~[ast::attribute]) -> CrateAttrs {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_desc(attrs: ~[ast::attribute]) -> Option<~str> {
|
pub fn parse_desc(attrs: ~[ast::attribute]) -> Option<~str> {
|
||||||
let doc_strs = do doc_metas(attrs).filter_mapped |meta| {
|
let doc_strs = do doc_metas(attrs).consume_iter().filter_map |meta| {
|
||||||
attr::get_meta_item_value_str(*meta).map(|s| s.to_owned())
|
attr::get_meta_item_value_str(meta).map(|s| s.to_owned())
|
||||||
};
|
}.collect::<~[~str]>();
|
||||||
if doc_strs.is_empty() {
|
if doc_strs.is_empty() {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
|
@ -13,8 +13,6 @@
|
|||||||
|
|
||||||
use doc;
|
use doc;
|
||||||
|
|
||||||
use std::vec;
|
|
||||||
|
|
||||||
pub type AstId = int;
|
pub type AstId = int;
|
||||||
|
|
||||||
#[deriving(Eq)]
|
#[deriving(Eq)]
|
||||||
@ -186,87 +184,64 @@ impl Doc {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
macro_rules! filt_mapper {
|
||||||
|
($vec:expr, $pat:pat) => {
|
||||||
|
do ($vec).iter().filter_map |thing| {
|
||||||
|
match thing {
|
||||||
|
&$pat => Some(copy *x),
|
||||||
|
_ => None
|
||||||
|
}
|
||||||
|
}.collect()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
macro_rules! md {
|
||||||
|
($id:ident) => {
|
||||||
|
filt_mapper!(self.items, $id(ref x))
|
||||||
|
}
|
||||||
|
}
|
||||||
/// Some helper methods on ModDoc, mostly for testing
|
/// Some helper methods on ModDoc, mostly for testing
|
||||||
impl ModDoc {
|
impl ModDoc {
|
||||||
pub fn mods(&self) -> ~[ModDoc] {
|
pub fn mods(&self) -> ~[ModDoc] {
|
||||||
do vec::filter_mapped(self.items) |itemtag| {
|
md!(ModTag)
|
||||||
match copy *itemtag {
|
|
||||||
ModTag(ModDoc) => Some(ModDoc),
|
|
||||||
_ => None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn nmods(&self) -> ~[NmodDoc] {
|
pub fn nmods(&self) -> ~[NmodDoc] {
|
||||||
do vec::filter_mapped(self.items) |itemtag| {
|
md!(NmodTag)
|
||||||
match copy *itemtag {
|
|
||||||
NmodTag(nModDoc) => Some(nModDoc),
|
|
||||||
_ => None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn fns(&self) -> ~[FnDoc] {
|
pub fn fns(&self) -> ~[FnDoc] {
|
||||||
do vec::filter_mapped(self.items) |itemtag| {
|
md!(FnTag)
|
||||||
match copy *itemtag {
|
|
||||||
FnTag(FnDoc) => Some(FnDoc),
|
|
||||||
_ => None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn consts(&self) -> ~[ConstDoc] {
|
pub fn consts(&self) -> ~[ConstDoc] {
|
||||||
do vec::filter_mapped(self.items) |itemtag| {
|
md!(ConstTag)
|
||||||
match copy *itemtag {
|
|
||||||
ConstTag(ConstDoc) => Some(ConstDoc),
|
|
||||||
_ => None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn enums(&self) -> ~[EnumDoc] {
|
pub fn enums(&self) -> ~[EnumDoc] {
|
||||||
do vec::filter_mapped(self.items) |itemtag| {
|
md!(EnumTag)
|
||||||
match copy *itemtag {
|
|
||||||
EnumTag(EnumDoc) => Some(EnumDoc),
|
|
||||||
_ => None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn traits(&self) -> ~[TraitDoc] {
|
pub fn traits(&self) -> ~[TraitDoc] {
|
||||||
do vec::filter_mapped(self.items) |itemtag| {
|
md!(TraitTag)
|
||||||
match copy *itemtag {
|
|
||||||
TraitTag(TraitDoc) => Some(TraitDoc),
|
|
||||||
_ => None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn impls(&self) -> ~[ImplDoc] {
|
pub fn impls(&self) -> ~[ImplDoc] {
|
||||||
do vec::filter_mapped(self.items) |itemtag| {
|
md!(ImplTag)
|
||||||
match copy *itemtag {
|
|
||||||
ImplTag(ImplDoc) => Some(ImplDoc),
|
|
||||||
_ => None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn types(&self) -> ~[TyDoc] {
|
pub fn types(&self) -> ~[TyDoc] {
|
||||||
do vec::filter_mapped(self.items) |itemtag| {
|
md!(TyTag)
|
||||||
match copy *itemtag {
|
|
||||||
TyTag(TyDoc) => Some(TyDoc),
|
|
||||||
_ => None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn structs(&self) -> ~[StructDoc] {
|
pub fn structs(&self) -> ~[StructDoc] {
|
||||||
do vec::filter_mapped(self.items) |itemtag| {
|
md!(StructTag)
|
||||||
match copy *itemtag {
|
}
|
||||||
StructTag(StructDoc) => Some(StructDoc),
|
}
|
||||||
_ => None
|
|
||||||
}
|
macro_rules! pu {
|
||||||
}
|
($id:ident) => {
|
||||||
|
filt_mapper!(*self, ItemPage($id(ref x)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -284,75 +259,35 @@ pub trait PageUtils {
|
|||||||
impl PageUtils for ~[Page] {
|
impl PageUtils for ~[Page] {
|
||||||
|
|
||||||
fn mods(&self) -> ~[ModDoc] {
|
fn mods(&self) -> ~[ModDoc] {
|
||||||
do vec::filter_mapped(*self) |page| {
|
pu!(ModTag)
|
||||||
match copy *page {
|
|
||||||
ItemPage(ModTag(ModDoc)) => Some(ModDoc),
|
|
||||||
_ => None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn nmods(&self) -> ~[NmodDoc] {
|
fn nmods(&self) -> ~[NmodDoc] {
|
||||||
do vec::filter_mapped(*self) |page| {
|
pu!(NmodTag)
|
||||||
match copy *page {
|
|
||||||
ItemPage(NmodTag(nModDoc)) => Some(nModDoc),
|
|
||||||
_ => None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fns(&self) -> ~[FnDoc] {
|
fn fns(&self) -> ~[FnDoc] {
|
||||||
do vec::filter_mapped(*self) |page| {
|
pu!(FnTag)
|
||||||
match copy *page {
|
|
||||||
ItemPage(FnTag(FnDoc)) => Some(FnDoc),
|
|
||||||
_ => None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn consts(&self) -> ~[ConstDoc] {
|
fn consts(&self) -> ~[ConstDoc] {
|
||||||
do vec::filter_mapped(*self) |page| {
|
pu!(ConstTag)
|
||||||
match copy *page {
|
|
||||||
ItemPage(ConstTag(ConstDoc)) => Some(ConstDoc),
|
|
||||||
_ => None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn enums(&self) -> ~[EnumDoc] {
|
fn enums(&self) -> ~[EnumDoc] {
|
||||||
do vec::filter_mapped(*self) |page| {
|
pu!(EnumTag)
|
||||||
match copy *page {
|
|
||||||
ItemPage(EnumTag(EnumDoc)) => Some(EnumDoc),
|
|
||||||
_ => None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn traits(&self) -> ~[TraitDoc] {
|
fn traits(&self) -> ~[TraitDoc] {
|
||||||
do vec::filter_mapped(*self) |page| {
|
pu!(TraitTag)
|
||||||
match copy *page {
|
|
||||||
ItemPage(TraitTag(TraitDoc)) => Some(TraitDoc),
|
|
||||||
_ => None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn impls(&self) -> ~[ImplDoc] {
|
fn impls(&self) -> ~[ImplDoc] {
|
||||||
do vec::filter_mapped(*self) |page| {
|
pu!(ImplTag)
|
||||||
match copy *page {
|
|
||||||
ItemPage(ImplTag(ImplDoc)) => Some(ImplDoc),
|
|
||||||
_ => None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn types(&self) -> ~[TyDoc] {
|
fn types(&self) -> ~[TyDoc] {
|
||||||
do vec::filter_mapped(*self) |page| {
|
pu!(TyTag)
|
||||||
match copy *page {
|
|
||||||
ItemPage(TyTag(TyDoc)) => Some(TyDoc),
|
|
||||||
_ => None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,7 +15,6 @@ use astsrv;
|
|||||||
use doc::ItemUtils;
|
use doc::ItemUtils;
|
||||||
use doc;
|
use doc;
|
||||||
|
|
||||||
use std::vec;
|
|
||||||
use syntax::ast;
|
use syntax::ast;
|
||||||
use syntax::parse::token::{ident_interner, ident_to_str};
|
use syntax::parse::token::{ident_interner, ident_to_str};
|
||||||
use syntax::parse::token;
|
use syntax::parse::token;
|
||||||
@ -83,7 +82,7 @@ fn moddoc_from_mod(
|
|||||||
) -> doc::ModDoc {
|
) -> doc::ModDoc {
|
||||||
doc::ModDoc {
|
doc::ModDoc {
|
||||||
item: itemdoc,
|
item: itemdoc,
|
||||||
items: do vec::filter_mapped(module_.items) |item| {
|
items: do module_.items.iter().filter_map |item| {
|
||||||
let ItemDoc = mk_itemdoc(item.id, to_str(item.ident));
|
let ItemDoc = mk_itemdoc(item.id, to_str(item.ident));
|
||||||
match copy item.node {
|
match copy item.node {
|
||||||
ast::item_mod(m) => {
|
ast::item_mod(m) => {
|
||||||
@ -133,7 +132,7 @@ fn moddoc_from_mod(
|
|||||||
}
|
}
|
||||||
_ => None
|
_ => None
|
||||||
}
|
}
|
||||||
},
|
}.collect(),
|
||||||
index: None
|
index: None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -128,13 +128,12 @@ 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 doc.items.filtered |item| {
|
items: do doc.items.iter().filter |item| {
|
||||||
match *item {
|
match **item {
|
||||||
doc::ModTag(_) => false,
|
doc::ModTag(_) | doc::NmodTag(_) => false,
|
||||||
doc::NmodTag(_) => false,
|
|
||||||
_ => true
|
_ => true
|
||||||
}
|
}
|
||||||
},
|
}.transform(|x| copy *x).collect::<~[doc::ItemTag]>(),
|
||||||
.. copy doc
|
.. copy doc
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,9 +41,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.filtered |ItemTag| {
|
items: do doc.items.iter().filter |item_tag| {
|
||||||
!is_hidden(fold.ctxt.clone(), ItemTag.item())
|
!is_hidden(fold.ctxt.clone(), item_tag.item())
|
||||||
},
|
}.transform(|x| copy *x).collect(),
|
||||||
.. doc
|
.. doc
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -80,7 +80,7 @@ fn strip_priv_methods(
|
|||||||
methods: &[@ast::method],
|
methods: &[@ast::method],
|
||||||
item_vis: ast::visibility
|
item_vis: ast::visibility
|
||||||
) -> doc::ImplDoc {
|
) -> doc::ImplDoc {
|
||||||
let methods = do (&doc.methods).filtered |method| {
|
let methods = do doc.methods.iter().filter |method| {
|
||||||
let ast_method = do methods.iter().find_ |m| {
|
let ast_method = do methods.iter().find_ |m| {
|
||||||
extract::to_str(m.ident) == method.name
|
extract::to_str(m.ident) == method.name
|
||||||
};
|
};
|
||||||
@ -91,7 +91,7 @@ fn strip_priv_methods(
|
|||||||
ast::private => false,
|
ast::private => false,
|
||||||
ast::inherited => item_vis == ast::public
|
ast::inherited => item_vis == ast::public
|
||||||
}
|
}
|
||||||
};
|
}.transform(|x| copy *x).collect();
|
||||||
|
|
||||||
doc::ImplDoc {
|
doc::ImplDoc {
|
||||||
methods: methods,
|
methods: methods,
|
||||||
@ -106,9 +106,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: doc.items.filtered(|ItemTag| {
|
items: doc.items.iter().filter(|item_tag| {
|
||||||
match ItemTag {
|
match item_tag {
|
||||||
&doc::ImplTag(ref doc) => {
|
& &doc::ImplTag(ref doc) => {
|
||||||
if doc.trait_types.is_empty() {
|
if doc.trait_types.is_empty() {
|
||||||
// This is an associated impl. We have already pruned the
|
// This is an associated impl. We have already pruned the
|
||||||
// non-visible methods. If there are any left then
|
// non-visible methods. If there are any left then
|
||||||
@ -123,10 +123,10 @@ fn fold_mod(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
is_visible(fold.ctxt.clone(), ItemTag.item())
|
is_visible(fold.ctxt.clone(), item_tag.item())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}),
|
}).transform(|x| copy *x).collect(),
|
||||||
.. doc
|
.. doc
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -77,9 +77,9 @@ fn fold_mod(_ctx: @mut ReadyCtx,
|
|||||||
fold: @fold::ast_fold) -> ast::_mod {
|
fold: @fold::ast_fold) -> ast::_mod {
|
||||||
fn strip_main(item: @ast::item) -> @ast::item {
|
fn strip_main(item: @ast::item) -> @ast::item {
|
||||||
@ast::item {
|
@ast::item {
|
||||||
attrs: do item.attrs.filtered |attr| {
|
attrs: do item.attrs.iter().filter_map |attr| {
|
||||||
"main" != attr::get_attr_name(attr)
|
if "main" != attr::get_attr_name(attr) {Some(*attr)} else {None}
|
||||||
},
|
}.collect(),
|
||||||
.. copy *item
|
.. copy *item
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,6 +34,7 @@ pub fn each_pkg_parent_workspace(pkgid: &PkgId, action: &fn(&Path) -> bool) -> b
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn pkg_parent_workspaces(pkgid: &PkgId) -> ~[Path] {
|
pub fn pkg_parent_workspaces(pkgid: &PkgId) -> ~[Path] {
|
||||||
rust_path().filtered(|ws|
|
rust_path().consume_iter()
|
||||||
workspace_contains_package_id(pkgid, ws))
|
.filter(|ws| workspace_contains_package_id(pkgid, ws))
|
||||||
|
.collect()
|
||||||
}
|
}
|
||||||
|
@ -777,9 +777,9 @@ pub fn list_dir(p: &Path) -> ~[~str] {
|
|||||||
strings
|
strings
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
do get_list(p).filtered |filename| {
|
do get_list(p).consume_iter().filter |filename| {
|
||||||
*filename != ~"." && *filename != ~".."
|
"." != *filename && ".." != *filename
|
||||||
}
|
}.collect()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -309,77 +309,6 @@ pub fn flat_map<T, U>(v: &[T], f: &fn(t: &T) -> ~[U]) -> ~[U] {
|
|||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn filter_map<T, U>(
|
|
||||||
v: ~[T],
|
|
||||||
f: &fn(t: T) -> Option<U>) -> ~[U]
|
|
||||||
{
|
|
||||||
/*!
|
|
||||||
*
|
|
||||||
* Apply a function to each element of a vector and return the results.
|
|
||||||
* Consumes the input vector. If function `f` returns `None` then that
|
|
||||||
* element is excluded from the resulting vector.
|
|
||||||
*/
|
|
||||||
|
|
||||||
let mut result = ~[];
|
|
||||||
for v.consume_iter().advance |elem| {
|
|
||||||
match f(elem) {
|
|
||||||
None => {}
|
|
||||||
Some(result_elem) => { result.push(result_elem); }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
result
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn filter_mapped<T, U: Copy>(
|
|
||||||
v: &[T],
|
|
||||||
f: &fn(t: &T) -> Option<U>) -> ~[U]
|
|
||||||
{
|
|
||||||
/*!
|
|
||||||
*
|
|
||||||
* Like `filter_map()`, but operates on a borrowed slice
|
|
||||||
* and does not consume the input.
|
|
||||||
*/
|
|
||||||
|
|
||||||
let mut result = ~[];
|
|
||||||
for v.iter().advance |elem| {
|
|
||||||
match f(elem) {
|
|
||||||
None => {/* no-op */ }
|
|
||||||
Some(result_elem) => { result.push(result_elem); }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
result
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Construct a new vector from the elements of a vector for which some
|
|
||||||
* predicate holds.
|
|
||||||
*
|
|
||||||
* Apply function `f` to each element of `v` and return a vector containing
|
|
||||||
* only those elements for which `f` returned true.
|
|
||||||
*/
|
|
||||||
pub fn filter<T>(v: ~[T], f: &fn(t: &T) -> bool) -> ~[T] {
|
|
||||||
let mut result = ~[];
|
|
||||||
for v.consume_iter().advance |elem| {
|
|
||||||
if f(&elem) { result.push(elem); }
|
|
||||||
}
|
|
||||||
result
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Construct a new vector from the elements of a vector for which some
|
|
||||||
* predicate holds.
|
|
||||||
*
|
|
||||||
* Apply function `f` to each element of `v` and return a vector containing
|
|
||||||
* only those elements for which `f` returned true.
|
|
||||||
*/
|
|
||||||
pub fn filtered<T:Copy>(v: &[T], f: &fn(t: &T) -> bool) -> ~[T] {
|
|
||||||
let mut result = ~[];
|
|
||||||
for v.iter().advance |elem| {
|
|
||||||
if f(elem) { result.push(copy *elem); }
|
|
||||||
}
|
|
||||||
result
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Flattens a vector of vectors of T into a single vector of T.
|
/// Flattens a vector of vectors of T into a single vector of T.
|
||||||
pub fn concat<T:Copy>(v: &[~[T]]) -> ~[T] { v.concat_vec() }
|
pub fn concat<T:Copy>(v: &[~[T]]) -> ~[T] { v.concat_vec() }
|
||||||
|
|
||||||
@ -866,7 +795,6 @@ pub trait ImmutableVector<'self, T> {
|
|||||||
fn last_opt(&self) -> Option<&'self T>;
|
fn last_opt(&self) -> Option<&'self T>;
|
||||||
fn rposition(&self, f: &fn(t: &T) -> bool) -> Option<uint>;
|
fn rposition(&self, f: &fn(t: &T) -> bool) -> Option<uint>;
|
||||||
fn flat_map<U>(&self, f: &fn(t: &T) -> ~[U]) -> ~[U];
|
fn flat_map<U>(&self, f: &fn(t: &T) -> ~[U]) -> ~[U];
|
||||||
fn filter_mapped<U:Copy>(&self, f: &fn(t: &T) -> Option<U>) -> ~[U];
|
|
||||||
unsafe fn unsafe_ref(&self, index: uint) -> *T;
|
unsafe fn unsafe_ref(&self, index: uint) -> *T;
|
||||||
|
|
||||||
fn bsearch(&self, f: &fn(&T) -> Ordering) -> Option<uint>;
|
fn bsearch(&self, f: &fn(&T) -> Ordering) -> Option<uint>;
|
||||||
@ -976,17 +904,6 @@ impl<'self,T> ImmutableVector<'self, T> for &'self [T] {
|
|||||||
fn flat_map<U>(&self, f: &fn(t: &T) -> ~[U]) -> ~[U] {
|
fn flat_map<U>(&self, f: &fn(t: &T) -> ~[U]) -> ~[U] {
|
||||||
flat_map(*self, f)
|
flat_map(*self, f)
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
* Apply a function to each element of a vector and return the results
|
|
||||||
*
|
|
||||||
* If function `f` returns `none` then that element is excluded from
|
|
||||||
* the resulting vector.
|
|
||||||
*/
|
|
||||||
#[inline]
|
|
||||||
fn filter_mapped<U:Copy>(&self, f: &fn(t: &T) -> Option<U>) -> ~[U] {
|
|
||||||
filter_mapped(*self, f)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns a pointer to the element at the given index, without doing
|
/// Returns a pointer to the element at the given index, without doing
|
||||||
/// bounds checking.
|
/// bounds checking.
|
||||||
#[inline]
|
#[inline]
|
||||||
@ -1077,25 +994,12 @@ impl<'self, T: TotalOrd> ImmutableTotalOrdVector<T> for &'self [T] {
|
|||||||
|
|
||||||
#[allow(missing_doc)]
|
#[allow(missing_doc)]
|
||||||
pub trait ImmutableCopyableVector<T> {
|
pub trait ImmutableCopyableVector<T> {
|
||||||
fn filtered(&self, f: &fn(&T) -> bool) -> ~[T];
|
|
||||||
fn partitioned(&self, f: &fn(&T) -> bool) -> (~[T], ~[T]);
|
fn partitioned(&self, f: &fn(&T) -> bool) -> (~[T], ~[T]);
|
||||||
unsafe fn unsafe_get(&self, elem: uint) -> T;
|
unsafe fn unsafe_get(&self, elem: uint) -> T;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Extension methods for vectors
|
/// Extension methods for vectors
|
||||||
impl<'self,T:Copy> ImmutableCopyableVector<T> for &'self [T] {
|
impl<'self,T:Copy> ImmutableCopyableVector<T> for &'self [T] {
|
||||||
/**
|
|
||||||
* Construct a new vector from the elements of a vector for which some
|
|
||||||
* predicate holds.
|
|
||||||
*
|
|
||||||
* Apply function `f` to each element of `v` and return a vector
|
|
||||||
* containing only those elements for which `f` returned true.
|
|
||||||
*/
|
|
||||||
#[inline]
|
|
||||||
fn filtered(&self, f: &fn(t: &T) -> bool) -> ~[T] {
|
|
||||||
filtered(*self, f)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Partitions the vector into those that satisfies the predicate, and
|
* Partitions the vector into those that satisfies the predicate, and
|
||||||
* those that do not.
|
* those that do not.
|
||||||
@ -1144,7 +1048,6 @@ pub trait OwnedVector<T> {
|
|||||||
fn swap_remove(&mut self, index: uint) -> T;
|
fn swap_remove(&mut self, index: uint) -> T;
|
||||||
fn truncate(&mut self, newlen: uint);
|
fn truncate(&mut self, newlen: uint);
|
||||||
fn retain(&mut self, f: &fn(t: &T) -> bool);
|
fn retain(&mut self, f: &fn(t: &T) -> bool);
|
||||||
fn filter(self, f: &fn(t: &T) -> bool) -> ~[T];
|
|
||||||
fn partition(self, f: &fn(&T) -> bool) -> (~[T], ~[T]);
|
fn partition(self, f: &fn(&T) -> bool) -> (~[T], ~[T]);
|
||||||
fn grow_fn(&mut self, n: uint, op: &fn(uint) -> T);
|
fn grow_fn(&mut self, n: uint, op: &fn(uint) -> T);
|
||||||
}
|
}
|
||||||
@ -1482,11 +1385,6 @@ impl<T> OwnedVector<T> for ~[T] {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn filter(self, f: &fn(&T) -> bool) -> ~[T] {
|
|
||||||
filter(self, f)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Partitions the vector into those that satisfies the predicate, and
|
* Partitions the vector into those that satisfies the predicate, and
|
||||||
* those that do not.
|
* those that do not.
|
||||||
@ -2616,87 +2514,6 @@ mod tests {
|
|||||||
assert_eq!(w[4], 25u);
|
assert_eq!(w[4], 25u);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_filter_mapped() {
|
|
||||||
// Test on-stack filter-map.
|
|
||||||
let mut v = ~[1u, 2u, 3u];
|
|
||||||
let mut w = filter_mapped(v, square_if_odd_r);
|
|
||||||
assert_eq!(w.len(), 2u);
|
|
||||||
assert_eq!(w[0], 1u);
|
|
||||||
assert_eq!(w[1], 9u);
|
|
||||||
|
|
||||||
// Test on-heap filter-map.
|
|
||||||
v = ~[1u, 2u, 3u, 4u, 5u];
|
|
||||||
w = filter_mapped(v, square_if_odd_r);
|
|
||||||
assert_eq!(w.len(), 3u);
|
|
||||||
assert_eq!(w[0], 1u);
|
|
||||||
assert_eq!(w[1], 9u);
|
|
||||||
assert_eq!(w[2], 25u);
|
|
||||||
|
|
||||||
fn halve(i: &int) -> Option<int> {
|
|
||||||
if *i % 2 == 0 {
|
|
||||||
Some::<int>(*i / 2)
|
|
||||||
} else {
|
|
||||||
None::<int>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fn halve_for_sure(i: &int) -> int { *i / 2 }
|
|
||||||
let all_even: ~[int] = ~[0, 2, 8, 6];
|
|
||||||
let all_odd1: ~[int] = ~[1, 7, 3];
|
|
||||||
let all_odd2: ~[int] = ~[];
|
|
||||||
let mix: ~[int] = ~[9, 2, 6, 7, 1, 0, 0, 3];
|
|
||||||
let mix_dest: ~[int] = ~[1, 3, 0, 0];
|
|
||||||
assert!(filter_mapped(all_even, halve) ==
|
|
||||||
all_even.map(halve_for_sure));
|
|
||||||
assert_eq!(filter_mapped(all_odd1, halve), ~[]);
|
|
||||||
assert_eq!(filter_mapped(all_odd2, halve), ~[]);
|
|
||||||
assert_eq!(filter_mapped(mix, halve), mix_dest);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_filter_map() {
|
|
||||||
// Test on-stack filter-map.
|
|
||||||
let mut v = ~[1u, 2u, 3u];
|
|
||||||
let mut w = filter_map(v, square_if_odd_v);
|
|
||||||
assert_eq!(w.len(), 2u);
|
|
||||||
assert_eq!(w[0], 1u);
|
|
||||||
assert_eq!(w[1], 9u);
|
|
||||||
|
|
||||||
// Test on-heap filter-map.
|
|
||||||
v = ~[1u, 2u, 3u, 4u, 5u];
|
|
||||||
w = filter_map(v, square_if_odd_v);
|
|
||||||
assert_eq!(w.len(), 3u);
|
|
||||||
assert_eq!(w[0], 1u);
|
|
||||||
assert_eq!(w[1], 9u);
|
|
||||||
assert_eq!(w[2], 25u);
|
|
||||||
|
|
||||||
fn halve(i: int) -> Option<int> {
|
|
||||||
if i % 2 == 0 {
|
|
||||||
Some::<int>(i / 2)
|
|
||||||
} else {
|
|
||||||
None::<int>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fn halve_for_sure(i: &int) -> int { *i / 2 }
|
|
||||||
let all_even: ~[int] = ~[0, 2, 8, 6];
|
|
||||||
let all_even0: ~[int] = copy all_even;
|
|
||||||
let all_odd1: ~[int] = ~[1, 7, 3];
|
|
||||||
let all_odd2: ~[int] = ~[];
|
|
||||||
let mix: ~[int] = ~[9, 2, 6, 7, 1, 0, 0, 3];
|
|
||||||
let mix_dest: ~[int] = ~[1, 3, 0, 0];
|
|
||||||
assert!(filter_map(all_even, halve) ==
|
|
||||||
all_even0.map(halve_for_sure));
|
|
||||||
assert_eq!(filter_map(all_odd1, halve), ~[]);
|
|
||||||
assert_eq!(filter_map(all_odd2, halve), ~[]);
|
|
||||||
assert_eq!(filter_map(mix, halve), mix_dest);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_filter() {
|
|
||||||
assert_eq!(filter(~[1u, 2u, 3u], is_odd), ~[1u, 3u]);
|
|
||||||
assert_eq!(filter(~[1u, 2u, 4u, 8u, 16u], is_three), ~[]);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_retain() {
|
fn test_retain() {
|
||||||
let mut v = ~[1, 2, 3, 4, 5];
|
let mut v = ~[1, 2, 3, 4, 5];
|
||||||
@ -3227,38 +3044,6 @@ mod tests {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
#[ignore(windows)]
|
|
||||||
#[should_fail]
|
|
||||||
#[allow(non_implicitly_copyable_typarams)]
|
|
||||||
fn test_filter_mapped_fail() {
|
|
||||||
let v = [(~0, @0), (~0, @0), (~0, @0), (~0, @0)];
|
|
||||||
let mut i = 0;
|
|
||||||
do filter_mapped(v) |_elt| {
|
|
||||||
if i == 2 {
|
|
||||||
fail!()
|
|
||||||
}
|
|
||||||
i += 0;
|
|
||||||
Some((~0, @0))
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
#[ignore(windows)]
|
|
||||||
#[should_fail]
|
|
||||||
#[allow(non_implicitly_copyable_typarams)]
|
|
||||||
fn test_filter_fail() {
|
|
||||||
let v = [(~0, @0), (~0, @0), (~0, @0), (~0, @0)];
|
|
||||||
let mut i = 0;
|
|
||||||
do v.filtered |_elt| {
|
|
||||||
if i == 2 {
|
|
||||||
fail!()
|
|
||||||
}
|
|
||||||
i += 0;
|
|
||||||
true
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[ignore(windows)]
|
#[ignore(windows)]
|
||||||
#[should_fail]
|
#[should_fail]
|
||||||
|
@ -238,12 +238,12 @@ pub fn unguarded_pat(a: &arm) -> Option<~[@pat]> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn public_methods(ms: ~[@method]) -> ~[@method] {
|
pub fn public_methods(ms: ~[@method]) -> ~[@method] {
|
||||||
do ms.filtered |m| {
|
do ms.consume_iter().filter |m| {
|
||||||
match m.vis {
|
match m.vis {
|
||||||
public => true,
|
public => true,
|
||||||
_ => false
|
_ => false
|
||||||
}
|
}
|
||||||
}
|
}.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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
|
||||||
|
@ -143,13 +143,13 @@ pub fn get_name_value_str_pair(item: @ast::meta_item)
|
|||||||
/// Search a list of attributes and return only those with a specific name
|
/// Search a list of attributes and return only those with a specific name
|
||||||
pub fn find_attrs_by_name(attrs: &[ast::attribute], name: &str) ->
|
pub fn find_attrs_by_name(attrs: &[ast::attribute], name: &str) ->
|
||||||
~[ast::attribute] {
|
~[ast::attribute] {
|
||||||
do vec::filter_mapped(attrs) |a| {
|
do attrs.iter().filter_map |a| {
|
||||||
if name == get_attr_name(a) {
|
if name == get_attr_name(a) {
|
||||||
Some(*a)
|
Some(*a)
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Search a list of meta items and return only those with a specific name
|
/// Search a list of meta items and return only those with a specific name
|
||||||
@ -277,14 +277,7 @@ pub fn sort_meta_items(items: &[@ast::meta_item]) -> ~[@ast::meta_item] {
|
|||||||
|
|
||||||
pub fn remove_meta_items_by_name(items: ~[@ast::meta_item], name: &str) ->
|
pub fn remove_meta_items_by_name(items: ~[@ast::meta_item], name: &str) ->
|
||||||
~[@ast::meta_item] {
|
~[@ast::meta_item] {
|
||||||
|
items.consume_iter().filter(|item| name != get_meta_item_name(*item)).collect()
|
||||||
return vec::filter_mapped(items, |item| {
|
|
||||||
if name != get_meta_item_name(*item) {
|
|
||||||
Some(*item)
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -14,8 +14,6 @@ use codemap::{span, spanned};
|
|||||||
use parse::token;
|
use parse::token;
|
||||||
use opt_vec::OptVec;
|
use opt_vec::OptVec;
|
||||||
|
|
||||||
use std::vec;
|
|
||||||
|
|
||||||
pub trait ast_fold {
|
pub trait ast_fold {
|
||||||
fn fold_crate(@self, &crate) -> crate;
|
fn fold_crate(@self, &crate) -> crate;
|
||||||
fn fold_view_item(@self, @view_item) -> @view_item;
|
fn fold_view_item(@self, @view_item) -> @view_item;
|
||||||
@ -700,7 +698,7 @@ pub fn noop_fold_ty(t: &ty_, fld: @ast_fold) -> ty_ {
|
|||||||
pub fn noop_fold_mod(m: &_mod, fld: @ast_fold) -> _mod {
|
pub fn noop_fold_mod(m: &_mod, fld: @ast_fold) -> _mod {
|
||||||
ast::_mod {
|
ast::_mod {
|
||||||
view_items: m.view_items.iter().transform(|x| fld.fold_view_item(*x)).collect(),
|
view_items: m.view_items.iter().transform(|x| fld.fold_view_item(*x)).collect(),
|
||||||
items: vec::filter_mapped(m.items, |x| fld.fold_item(*x)),
|
items: m.items.iter().filter_map(|x| fld.fold_item(*x)).collect(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ use std::io::WriterUtil;
|
|||||||
|
|
||||||
// Make sure this import is warned about when at least one of its imported names
|
// Make sure this import is warned about when at least one of its imported names
|
||||||
// is unused
|
// is unused
|
||||||
use std::vec::{filter, from_elem}; //~ ERROR unused import
|
use std::vec::{from_fn, from_elem}; //~ ERROR unused import
|
||||||
|
|
||||||
mod foo {
|
mod foo {
|
||||||
pub struct Point{x: int, y: int}
|
pub struct Point{x: int, y: int}
|
||||||
|
Loading…
Reference in New Issue
Block a user