]> git.lizzy.rs Git - rust.git/commitdiff
Remove vec::{map, mapi, zip_map} and the methods, except for .map, since this
authorHuon Wilson <dbau.pp+github@gmail.com>
Sat, 29 Jun 2013 05:05:50 +0000 (15:05 +1000)
committerHuon Wilson <dbau.pp+github@gmail.com>
Sun, 30 Jun 2013 11:59:44 +0000 (21:59 +1000)
is very common, and the replacement (.iter().transform().collect()) is very
ugly.

47 files changed:
src/compiletest/runtest.rs
src/libextra/fileinput.rs
src/libextra/getopts.rs
src/libextra/num/bigint.rs
src/libextra/par.rs
src/libextra/semver.rs
src/librustc/back/rpath.rs
src/librustc/front/config.rs
src/librustc/front/test.rs
src/librustc/metadata/encoder.rs
src/librustc/middle/check_match.rs
src/librustc/middle/const_eval.rs
src/librustc/middle/lint.rs
src/librustc/middle/trans/adt.rs
src/librustc/middle/trans/build.rs
src/librustc/middle/trans/cabi.rs
src/librustc/middle/trans/common.rs
src/librustc/middle/trans/expr.rs
src/librustc/middle/trans/monomorphize.rs
src/librustc/middle/ty.rs
src/librustc/middle/typeck/astconv.rs
src/librustc/middle/typeck/check/mod.rs
src/librustc/middle/typeck/collect.rs
src/librustc/middle/typeck/infer/region_inference.rs
src/librustdoc/attr_pass.rs
src/librustdoc/extract.rs
src/librustdoc/fold.rs
src/librustdoc/tystr_pass.rs
src/libstd/io.rs
src/libstd/iterator.rs
src/libstd/tuple.rs
src/libstd/vec.rs
src/libsyntax/ast_util.rs
src/libsyntax/ext/deriving/decodable.rs
src/libsyntax/ext/deriving/generic.rs
src/libsyntax/ext/deriving/rand.rs
src/libsyntax/ext/pipes/pipec.rs
src/libsyntax/ext/source_util.rs
src/libsyntax/ext/tt/macro_parser.rs
src/libsyntax/fold.rs
src/test/bench/graph500-bfs.rs
src/test/bench/shootout-chameneos-redux.rs
src/test/bench/shootout-k-nucleotide-pipes.rs
src/test/compile-fail/lint-unused-imports.rs
src/test/run-pass/block-arg.rs
src/test/run-pass/block-vec-map_zip.rs [deleted file]
src/test/run-pass/trait-to-str.rs

index 0e04be34c795a7a4ac32e854b8be5a2bb53fd36c..715f6d91e09dd7e36cf58970729757c2cb0fffa2 100644 (file)
@@ -345,9 +345,9 @@ fn check_expected_errors(expected_errors: ~[errors::ExpectedError],
         fatal(~"process did not return an error status");
     }
 
-    let prefixes = vec::map(expected_errors, |ee| {
+    let prefixes = expected_errors.iter().transform(|ee| {
         fmt!("%s:%u:", testfile.to_str(), ee.line)
-    });
+    }).collect::<~[~str]>();
 
     // Scan and extract our error/warning messages,
     // which look like:
index 5367da2fa8d4feb93a0f14be563bbfef0d423c8e..f91260f475288539af5a7a6395bbe697ab3ac64a 100644 (file)
 use std::io::ReaderUtil;
 use std::io;
 use std::os;
-use std::vec;
 
 /**
 A summary of the internal state of a `FileInput` object. `line_num`
@@ -353,13 +352,13 @@ fn tell(&self) -> uint {
 */
 // XXX: stupid, unclear name
 pub fn pathify(vec: &[~str], stdin_hyphen : bool) -> ~[Option<Path>] {
-    vec::map(vec, |&str : & ~str| {
-        if stdin_hyphen && str == ~"-" {
+    vec.iter().transform(|str| {
+        if stdin_hyphen && "-" == *str {
             None
         } else {
-            Some(Path(str))
+            Some(Path(*str))
         }
-    })
+    }).collect()
 }
 
 /**
index 21fe676ef7929c00e64ad722c3183e8b45facaef..1a494f36c646960789294fa80b2594a7f995a35e 100644 (file)
@@ -592,9 +592,9 @@ pub fn getopts(args: &[~str], opts: &[OptGroup]) -> ::getopts::Result {
      */
     pub fn usage(brief: &str, opts: &[OptGroup]) -> ~str {
 
-        let desc_sep = ~"\n" + " ".repeat(24);
+        let desc_sep = "\n" + " ".repeat(24);
 
-        let rows = vec::map(opts, |optref| {
+        let mut rows = opts.iter().transform(|optref| {
             let OptGroup{short_name: short_name,
                          long_name: long_name,
                          hint: hint,
@@ -669,7 +669,7 @@ pub fn usage(brief: &str, opts: &[OptGroup]) -> ~str {
 
         return str::to_owned(brief) +
                "\n\nOptions:\n" +
-               rows.connect("\n") +
+               rows.collect::<~[~str]>().connect("\n") +
                "\n\n";
     }
 } // end groups module
index fd61c4f6bfc6c8e8829fec91d46f773e1efcbed4..9422ad0c9f2e0043b37f70f1223617f7c4df8a5a 100644 (file)
@@ -283,13 +283,13 @@ fn mul_digit(a: &BigUint, n: BigDigit) -> BigUint {
             if n == 1 { return copy *a; }
 
             let mut carry = 0;
-            let prod = do vec::map(a.data) |ai| {
+            let prod = do a.data.iter().transform |ai| {
                 let (hi, lo) = BigDigit::from_uint(
                     (*ai as uint) * (n as uint) + (carry as uint)
                 );
                 carry = hi;
                 lo
-            };
+            }.collect::<~[BigDigit]>();
             if carry == 0 { return BigUint::new(prod) };
             return BigUint::new(prod + [carry]);
         }
@@ -618,13 +618,13 @@ pub fn to_uint(&self) -> uint {
         if n_bits == 0 || self.is_zero() { return copy *self; }
 
         let mut carry = 0;
-        let shifted = do vec::map(self.data) |elem| {
+        let shifted = do self.data.iter().transform |elem| {
             let (hi, lo) = BigDigit::from_uint(
                 (*elem as uint) << n_bits | (carry as uint)
             );
             carry = hi;
             lo
-        };
+        }.collect::<~[BigDigit]>();
         if carry == 0 { return BigUint::new(shifted); }
         return BigUint::new(shifted + [carry]);
     }
@@ -1172,7 +1172,7 @@ fn check(slice: &[BigDigit], data: &[BigDigit]) {
 
     #[test]
     fn test_cmp() {
-        let data = [ &[], &[1], &[2], &[-1], &[0, 1], &[2, 1], &[1, 1, 1]  ]
+        let data: ~[BigUint] = [ &[], &[1], &[2], &[-1], &[0, 1], &[2, 1], &[1, 1, 1]  ]
             .map(|v| BigUint::from_slice(*v));
         for data.iter().enumerate().advance |(i, ni)| {
             for data.slice(i, data.len()).iter().enumerate().advance |(j0, nj)| {
index 665633eedf856cc3997f7283f36a6b10714ab6ad..2878a3ee12215c48f718cda16db559a98d4bfe23 100644 (file)
@@ -92,7 +92,7 @@ pub fn map<A:Copy + Send,B:Copy + Send>(
     vec::concat(map_slices(xs, || {
         let f = fn_factory();
         let result: ~fn(uint, &[A]) -> ~[B] =
-            |_, slice| vec::map(slice, |x| f(x));
+            |_, slice| slice.iter().transform(|x| f(x)).collect();
         result
     }))
 }
@@ -104,9 +104,9 @@ pub fn mapi<A:Copy + Send,B:Copy + Send>(
     let slices = map_slices(xs, || {
         let f = fn_factory();
         let result: ~fn(uint, &[A]) -> ~[B] = |base, slice| {
-            vec::mapi(slice, |i, x| {
+            slice.iter().enumerate().transform(|(i, x)| {
                 f(i + base, x)
-            })
+            }).collect()
         };
         result
     });
index 6361de1271934e240e1942e63cd3eaa69f4b8eb6..6c9453a5a3ba1140067c1286bc46c39ddfd342ae 100644 (file)
@@ -78,12 +78,12 @@ fn to_str(&self) -> ~str {
         let s = if self.pre.is_empty() {
             s
         } else {
-            s + "-" + self.pre.map(|i| i.to_str()).connect(".")
+            fmt!("%s-%s", s, self.pre.map(|i| i.to_str()).connect("."))
         };
         if self.build.is_empty() {
             s
         } else {
-            s + "+" + self.build.map(|i| i.to_str()).connect(".")
+            fmt!("%s+%s", s, self.build.map(|i| i.to_str()).connect("."))
         }
     }
 }
index ab107a8bf2509c79a2262f9afdacbd955e7f5930..19dbb941e556669f76022b301922fadef4d143a0 100644 (file)
@@ -52,7 +52,7 @@ fn get_sysroot_absolute_rt_lib(sess: session::Session) -> Path {
 }
 
 pub fn rpaths_to_flags(rpaths: &[Path]) -> ~[~str] {
-    vec::map(rpaths, |rpath| fmt!("-Wl,-rpath,%s",rpath.to_str()))
+    rpaths.iter().transform(|rpath| fmt!("-Wl,-rpath,%s",rpath.to_str())).collect()
 }
 
 fn get_rpaths(os: session::os,
@@ -103,9 +103,7 @@ fn log_rpaths(desc: &str, rpaths: &[Path]) {
 fn get_rpaths_relative_to_output(os: session::os,
                                  output: &Path,
                                  libs: &[Path]) -> ~[Path] {
-    vec::map(libs, |a| {
-        get_rpath_relative_to_output(os, output, a)
-    })
+    libs.iter().transform(|a| get_rpath_relative_to_output(os, output, a)).collect()
 }
 
 pub fn get_rpath_relative_to_output(os: session::os,
@@ -163,7 +161,7 @@ pub fn get_relative_to(abs1: &Path, abs2: &Path) -> Path {
 }
 
 fn get_absolute_rpaths(libs: &[Path]) -> ~[Path] {
-    vec::map(libs, |a| get_absolute_rpath(a) )
+    libs.iter().transform(|a| get_absolute_rpath(a)).collect()
 }
 
 pub fn get_absolute_rpath(lib: &Path) -> Path {
index 7d9fac5c6ae018605b0a0026efdf873d72740ed2..b1d4820f062eb797bd57d4d21c52460f0424c0bd 100644 (file)
@@ -90,7 +90,7 @@ fn fold_foreign_mod(
     ast::foreign_mod {
         sort: nm.sort,
         abis: nm.abis,
-        view_items: vec::map(filtered_view_items, |x| fld.fold_view_item(*x)),
+        view_items: filtered_view_items.iter().transform(|x| fld.fold_view_item(*x)).collect(),
         items: filtered_items
     }
 }
index cfd4df7403f69e928cbe82816e2120a8def05430..6998410bae0e52adf85079143b61afe2a0971bd5 100644 (file)
@@ -117,7 +117,7 @@ fn nomain(cx: @mut TestCtxt, item: @ast::item) -> @ast::item {
 
     let mod_nomain = ast::_mod {
         view_items: /*bad*/copy m.view_items,
-        items: vec::map(m.items, |i| nomain(cx, *i)),
+        items: m.items.iter().transform(|i| nomain(cx, *i)).collect(),
     };
 
     fold::noop_fold_mod(&mod_nomain, fld)
index 71d7bea0af7bc3327ba9314dc26780228a3c01f1..77a8d1792dbc8f667ba7e8fa97c95092bbc492a4 100644 (file)
@@ -1441,8 +1441,7 @@ fn get_ordered_deps(ecx: &EncodeContext, cstore: &cstore::CStore)
             expected_cnum += 1;
         }
 
-        // mut -> immutable hack for vec::map
-        deps.slice(0, deps.len()).to_owned()
+        deps
     }
 
     // We're just going to write a list of crate 'name-hash-version's, with
index 8cb671a97f4095740fff6e82f31a4ebd698493c3..72896258b2d326052e20bfc8e56369fc652b5bc7 100644 (file)
@@ -642,13 +642,13 @@ pub fn specialize(cx: &MatchCheckCtxt,
                                          ty_to_str(cx.tcx, left_ty)));
                             }
                         }
-                        let args = vec::map(class_fields, |class_field| {
+                        let args = class_fields.iter().transform(|class_field| {
                             match flds.iter().find_(|f|
                                             f.ident == class_field.ident) {
                                 Some(f) => f.pat,
                                 _ => wild()
                             }
-                        });
+                        }).collect();
                         Some(vec::append(args, vec::to_owned(r.tail())))
                     }
                 }
index 9d94a2de69334f40a95bb3b3c3513487514b15bf..bf91b6771dcd8110cf452d4704d35cdee20dbdd5 100644 (file)
@@ -19,7 +19,6 @@
 
 use std::float;
 use std::hashmap::{HashMap, HashSet};
-use std::vec;
 
 //
 // This pass classifies expressions by their constant-ness.
@@ -70,8 +69,8 @@ pub fn join(a: constness, b: constness) -> constness {
     }
 }
 
-pub fn join_all(cs: &[constness]) -> constness {
-    cs.iter().fold(integral_const, |a, b| join(a, *b))
+pub fn join_all<It: Iterator<constness>>(mut cs: It) -> constness {
+    cs.fold(integral_const, |a, b| join(a, b))
 }
 
 pub fn classify(e: &expr,
@@ -104,7 +103,7 @@ pub fn classify(e: &expr,
 
               ast::expr_tup(ref es) |
               ast::expr_vec(ref es, ast::m_imm) => {
-                join_all(vec::map(*es, |e| classify(*e, tcx)))
+                join_all(es.iter().transform(|e| classify(*e, tcx)))
               }
 
               ast::expr_vstore(e, vstore) => {
@@ -118,7 +117,7 @@ pub fn classify(e: &expr,
               }
 
               ast::expr_struct(_, ref fs, None) => {
-                let cs = do vec::map((*fs)) |f| {
+                let cs = do fs.iter().transform |f| {
                     classify(f.node.expr, tcx)
                 };
                 join_all(cs)
index d0fd516778bb61fdc99908636bcd217b7b6b8247..ce09f790ef45f4c2b626666328c18cb717f4c0b9 100644 (file)
@@ -740,11 +740,10 @@ fn check_ty(cx: &Context, ty: &ast::Ty) {
     }
 
     fn check_foreign_fn(cx: &Context, decl: &ast::fn_decl) {
-        let tys = vec::map(decl.inputs, |a| a.ty );
-        let r = vec::append_one(tys, decl.output);
-        for r.iter().advance |ty| {
-            check_ty(cx, *ty);
+        for decl.inputs.iter().advance |in| {
+            check_ty(cx, in.ty);
         }
+        check_ty(cx, decl.output)
     }
 
     match it.node {
index 5417d6f6cc6617e9f01bf6a18ea89d8ea0bfdf46..ab813c0ffc546cf410829db6defc079f8e7bd2b4 100644 (file)
@@ -519,10 +519,10 @@ pub fn trans_const(ccx: &mut CrateContext, r: &Repr, discr: int,
                 C_struct(build_const_struct(ccx, nonnull, vals))
             } else {
                 assert_eq!(vals.len(), 0);
-                let vals = do nonnull.fields.mapi |i, &ty| {
+                let vals = do nonnull.fields.iter().enumerate().transform |(i, &ty)| {
                     let llty = type_of::sizing_type_of(ccx, ty);
                     if i == ptrfield { C_null(llty) } else { C_undef(llty) }
-                };
+                }.collect::<~[ValueRef]>();
                 C_struct(build_const_struct(ccx, nonnull, vals))
             }
         }
index 46a8cb306f8b17beef7bbb53e239175d6edc6c39..8535c84c5cb5e30d4e839dab3bc4216b860671dd 100644 (file)
@@ -615,12 +615,12 @@ pub fn GEPi(cx: block, base: ValueRef, ixs: &[uint]) -> ValueRef {
     // we care about.
     if ixs.len() < 16 {
         let mut small_vec = [ C_i32(0), ..16 ];
-        for ixs.iter().enumerate().advance |(i, &ix)| {
-            small_vec[i] = C_i32(ix as i32)
+        for small_vec.mut_iter().zip(ixs.iter()).advance |(small_vec_e, &ix)| {
+            *small_vec_e = C_i32(ix as i32);
         }
         InBoundsGEP(cx, base, small_vec.slice(0, ixs.len()))
     } else {
-        let v = do vec::map(ixs) |i| { C_i32(*i as i32) };
+        let v = do ixs.iter().transform |i| { C_i32(*i as i32) }.collect::<~[ValueRef]>();
         count_insn(cx, "gepi");
         InBoundsGEP(cx, base, v)
     }
index 4cbc9cd417f271d4321e428d367b1293ce837be9..d00479194308b5f8475d66f54a1c7d9631a21325 100644 (file)
@@ -17,7 +17,6 @@
 
 use std::libc::c_uint;
 use std::option;
-use std::vec;
 
 pub trait ABIInfo {
     fn compute_info(&self, atys: &[Type], rty: Type, ret_def: bool) -> FnType;
@@ -37,7 +36,7 @@ pub struct FnType {
 
 impl FnType {
     pub fn decl_fn(&self, decl: &fn(fnty: Type) -> ValueRef) -> ValueRef {
-        let atys = vec::map(self.arg_tys, |t| t.ty);
+        let atys = self.arg_tys.iter().transform(|t| t.ty).collect::<~[Type]>();
         let rty = self.ret_ty.ty;
         let fnty = Type::func(atys, &rty);
         let llfn = decl(fnty);
index 539397c8b1a4d4927ac23cc5619e236b33cb7b71..5be8c63dba10d9482dda27e8bb03c741f05ab494 100644 (file)
@@ -980,9 +980,9 @@ pub fn node_id_type_params(bcx: block, id: ast::node_id) -> ~[ty::t] {
 
     match bcx.fcx.param_substs {
       Some(substs) => {
-        do vec::map(params) |t| {
+        do params.iter().transform |t| {
             ty::subst_tps(tcx, substs.tys, substs.self_ty, *t)
-        }
+        }.collect()
       }
       _ => params
     }
@@ -1006,9 +1006,11 @@ pub fn resolve_vtables_under_param_substs(tcx: ty::ctxt,
                                           param_substs: Option<@param_substs>,
                                           vts: typeck::vtable_res)
     -> typeck::vtable_res {
-    @vec::map(*vts, |ds|
-      @vec::map(**ds, |d|
-                resolve_vtable_under_param_substs(tcx, param_substs, copy *d)))
+    @vts.iter().transform(|ds|
+      @ds.iter().transform(
+          |d| resolve_vtable_under_param_substs(tcx, param_substs, copy *d))
+                          .collect::<~[typeck::vtable_origin]>())
+        .collect::<~[typeck::vtable_param_res]>()
 }
 
 
@@ -1029,9 +1031,9 @@ pub fn resolve_vtable_under_param_substs(tcx: ty::ctxt,
         typeck::vtable_static(trait_id, tys, sub) => {
             let tys = match param_substs {
                 Some(substs) => {
-                    do vec::map(tys) |t| {
+                    do tys.iter().transform |t| {
                         ty::subst_tps(tcx, substs.tys, substs.self_ty, *t)
-                    }
+                    }.collect()
                 }
                 _ => tys
             };
index 1511f25414071e2c052c162a234b33d31363efc3..df197ded629ea6210c62e0dc6637a9a219388d08 100644 (file)
@@ -588,8 +588,9 @@ fn trans_rvalue_dps_unadjusted(bcx: block, expr: @ast::expr,
         }
         ast::expr_tup(ref args) => {
             let repr = adt::represent_type(bcx.ccx(), expr_ty(bcx, expr));
-            return trans_adt(bcx, repr, 0, args.mapi(|i, arg| (i, *arg)),
-                             None, dest);
+            let numbered_fields: ~[(uint, @ast::expr)] =
+                args.iter().enumerate().transform(|(i, arg)| (i, *arg)).collect();
+            return trans_adt(bcx, repr, 0, numbered_fields, None, dest);
         }
         ast::expr_lit(@codemap::spanned {node: ast::lit_str(s), _}) => {
             return tvec::trans_lit_str(bcx, expr, s, dest);
index 4ae8554d7143ca2c8bbce254b1fd99e34c697377..ad48c30747edcc2dc1b68882817719b3ad74335b 100644 (file)
@@ -30,7 +30,6 @@
 use middle::typeck;
 use util::ppaux::{Repr,ty_to_str};
 
-use std::vec;
 use syntax::ast;
 use syntax::ast_map;
 use syntax::ast_map::path_name;
@@ -62,12 +61,12 @@ pub fn monomorphic_fn(ccx: @mut CrateContext,
     assert!(real_substs.tps.iter().all(|t| !ty::type_needs_infer(*t)));
     let _icx = push_ctxt("monomorphic_fn");
     let mut must_cast = false;
-    let substs = vec::map(real_substs.tps, |t| {
+    let substs = real_substs.tps.iter().transform(|t| {
         match normalize_for_monomorphization(ccx.tcx, *t) {
           Some(t) => { must_cast = true; t }
           None => *t
         }
-    });
+    }).collect::<~[ty::t]>();
 
     for real_substs.tps.iter().advance |s| { assert!(!ty::type_has_params(*s)); }
     for substs.iter().advance |s| { assert!(!ty::type_has_params(*s)); }
@@ -325,22 +324,22 @@ pub fn make_mono_id(ccx: @mut CrateContext,
                     vtables: Option<typeck::vtable_res>,
                     impl_did_opt: Option<ast::def_id>,
                     param_uses: Option<@~[type_use::type_uses]>) -> mono_id {
-    let precise_param_ids = match vtables {
+    // FIXME (possibly #5801): Need a lot of type hints to get
+    // .collect() to work.
+    let precise_param_ids: ~[(ty::t, Option<@~[mono_id]>)] = match vtables {
       Some(vts) => {
         debug!("make_mono_id vtables=%s substs=%s",
                vts.repr(ccx.tcx), substs.repr(ccx.tcx));
-        vec::map_zip(*vts, substs, |vtable, subst| {
+        vts.iter().zip(substs.iter()).transform(|(vtable, subst)| {
             let v = vtable.map(|vt| meth::vtable_id(ccx, vt));
             (*subst, if !v.is_empty() { Some(@v) } else { None })
-        })
-      }
-      None => {
-        vec::map(substs, |subst| (*subst, None))
+        }).collect()
       }
+      None => substs.iter().transform(|subst| (*subst, None::<@~[mono_id]>)).collect()
     };
     let param_ids = match param_uses {
       Some(ref uses) => {
-        vec::map_zip(precise_param_ids, **uses, |id, uses| {
+        precise_param_ids.iter().zip(uses.iter()).transform(|(id, uses)| {
             if ccx.sess.no_monomorphic_collapse() {
                 match copy *id {
                     (a, b) => mono_precise(a, b)
@@ -377,13 +376,13 @@ pub fn make_mono_id(ccx: @mut CrateContext,
                     }
                 }
             }
-        })
+        }).collect()
       }
       None => {
-          precise_param_ids.map(|x| {
+          precise_param_ids.iter().transform(|x| {
               let (a, b) = copy *x;
               mono_precise(a, b)
-          })
+          }).collect()
       }
     };
     @mono_id_ {def: item, params: param_ids, impl_did_opt: impl_did_opt}
index 8a6fff09c730b67841099ad86568fdfec6c2c317..bbf548d2659a1e77c2e501be71ce07f305fd0ffa 100644 (file)
@@ -3674,15 +3674,15 @@ pub fn substd_enum_variants(cx: ctxt,
                             id: ast::def_id,
                             substs: &substs)
                          -> ~[VariantInfo] {
-    do vec::map(*enum_variants(cx, id)) |variant_info| {
-        let substd_args = vec::map(variant_info.args,
-                                   |aty| subst(cx, substs, *aty));
+    do enum_variants(cx, id).iter().transform |variant_info| {
+        let substd_args = variant_info.args.iter()
+            .transform(|aty| subst(cx, substs, *aty)).collect();
 
         let substd_ctor_ty = subst(cx, substs, variant_info.ctor_ty);
 
         @VariantInfo_{args: substd_args, ctor_ty: substd_ctor_ty,
                       ../*bad*/copy **variant_info}
-    }
+    }.collect()
 }
 
 pub fn item_path_str(cx: ctxt, id: ast::def_id) -> ~str {
@@ -3815,7 +3815,7 @@ pub fn enum_variants(cx: ctxt, id: ast::def_id) -> @~[VariantInfo] {
                     _
                 }, _) => {
             let mut disr_val = -1;
-            @vec::map(enum_definition.variants, |variant| {
+            @enum_definition.variants.iter().transform(|variant| {
                 match variant.node.kind {
                     ast::tuple_variant_kind(ref args) => {
                         let ctor_ty = node_id_to_type(cx, variant.node.id);
@@ -3848,7 +3848,7 @@ pub fn enum_variants(cx: ctxt, id: ast::def_id) -> @~[VariantInfo] {
                         fail!("struct variant kinds unimpl in enum_variants")
                     }
                 }
-            })
+            }).collect()
           }
           _ => cx.sess.bug("tag_variants: id not bound to an enum")
         }
index 1d9895d29503843c737a6c8d35b19ac5b3206ee6..4d2849c521058a42faa3a3da503036256e0b21dc 100644 (file)
@@ -718,14 +718,14 @@ pub fn ty_of_closure<AC:AstConv,RS:region_scope + Copy + 'static>(
     let bound_lifetime_names = bound_lifetimes(this, lifetimes);
     let rb = in_binding_rscope(rscope, RegionParamNames(copy bound_lifetime_names));
 
-    let input_tys = do decl.inputs.mapi |i, a| {
+    let input_tys = do decl.inputs.iter().enumerate().transform |(i, a)| {
         let expected_arg_ty = do expected_sig.chain_ref |e| {
             // no guarantee that the correct number of expected args
             // were supplied
             if i < e.inputs.len() {Some(e.inputs[i])} else {None}
         };
         ty_of_arg(this, &rb, *a, expected_arg_ty)
-    };
+    }.collect();
 
     let expected_ret_ty = expected_sig.map(|e| e.output);
     let output_ty = match decl.output.node {
index d1edc1cd3630d4ec8ad6d424d03aa3289d36a1c2..91b8f01f33623644d47bd6709ea163383e836ead 100644 (file)
@@ -1781,7 +1781,7 @@ fn check_field(fcx: @mut FnCtxt,
             _ => ()
         }
 
-        let tps = vec::map(tys, |ty| fcx.to_ty(*ty));
+        let tps = tys.iter().transform(|ty| fcx.to_ty(*ty)).collect::<~[ty::t]>();
         match method::lookup(fcx,
                              expr,
                              base,
@@ -2766,7 +2766,7 @@ fn types_compatible(fcx: @mut FnCtxt, sp: span,
         let mut bot_field = false;
         let mut err_field = false;
 
-        let elt_ts = do elts.mapi |i, e| {
+        let elt_ts = do elts.iter().enumerate().transform |(i, e)| {
             let opt_hint = match flds {
                 Some(ref fs) if i < fs.len() => Some(fs[i]),
                 _ => None
@@ -2776,7 +2776,7 @@ fn types_compatible(fcx: @mut FnCtxt, sp: span,
             err_field = err_field || ty::type_is_error(t);
             bot_field = bot_field || ty::type_is_bot(t);
             t
-        };
+        }.collect();
         if bot_field {
             fcx.write_bot(id);
         } else if err_field {
index 3a4fa82906d1668f8da371ec1ea7eccf50e8e601..85bd2bc2d75ea28c1f5436cac7c8ce12693a43a0 100644 (file)
@@ -712,7 +712,7 @@ pub fn convert_methods(ccx: &CrateCtxt,
                     -> ~[ConvertedMethod]
 {
     let tcx = ccx.tcx;
-    return vec::map(ms, |m| {
+    return ms.iter().transform(|m| {
         let num_rcvr_ty_params = rcvr_ty_generics.type_param_defs.len();
         let m_ty_generics =
             ty_generics(ccx, rcvr_ty_generics.region_param, &m.generics,
@@ -742,7 +742,7 @@ pub fn convert_methods(ccx: &CrateCtxt,
         tcx.methods.insert(mty.def_id, mty);
         ConvertedMethod {mty: mty, id: m.id,
                          span: m.span, body_id: m.body.node.id}
-    });
+    }).collect();
 
     fn ty_of_method(ccx: &CrateCtxt,
                     m: &ast::method,
index bad4cb2fe8772a25597a47ecf03745512d9590ec..db17405fc26639cc70f082f75ec478bcbbbd8f30 100644 (file)
@@ -1478,7 +1478,7 @@ pub fn extract_values_and_report_conflicts(&mut self, graph: &Graph)
         // overlapping locations.
         let mut dup_vec = graph.nodes.map(|_| uint::max_value);
 
-        graph.nodes.mapi(|idx, node| {
+        graph.nodes.iter().enumerate().transform(|(idx, node)| {
             match node.value {
                 Value(_) => {
                     /* Inference successful */
@@ -1528,7 +1528,7 @@ pub fn extract_values_and_report_conflicts(&mut self, graph: &Graph)
             }
 
             node.value
-        })
+        }).collect()
     }
 
     pub fn report_error_for_expanding_node(&mut self,
index 3efebe854e48a6be8e0d0d9355647b00675f502f..2a9442fbe525b51812c155c09b45e87457f47341 100644 (file)
@@ -26,7 +26,6 @@
 use fold;
 use pass::Pass;
 
-use std::vec;
 use syntax::ast;
 use syntax::ast_map;
 
@@ -124,7 +123,7 @@ fn fold_enum(
     let doc = fold::default_seq_fold_enum(fold, doc);
 
     doc::EnumDoc {
-        variants: do vec::map(doc.variants) |variant| {
+        variants: do doc.variants.iter().transform |variant| {
             let variant = copy *variant;
             let desc = {
                 let variant = copy variant;
@@ -153,7 +152,7 @@ fn fold_enum(
                 desc: desc,
                 .. variant
             }
-        },
+        }.collect(),
         .. doc
     }
 }
@@ -183,7 +182,7 @@ fn merge_method_attrs(
             ast_map::node_item(@ast::item {
                 node: ast::item_trait(_, _, ref methods), _
             }, _) => {
-                vec::map(*methods, |method| {
+                methods.iter().transform(|method| {
                     match copy *method {
                         ast::required(ty_m) => {
                             (to_str(ty_m.ident),
@@ -193,21 +192,21 @@ fn merge_method_attrs(
                             (to_str(m.ident), attr_parser::parse_desc(copy m.attrs))
                         }
                     }
-                })
+                }).collect()
             }
             ast_map::node_item(@ast::item {
                 node: ast::item_impl(_, _, _, ref methods), _
             }, _) => {
-                vec::map(*methods, |method| {
+                methods.iter().transform(|method| {
                     (to_str(method.ident),
                      attr_parser::parse_desc(copy method.attrs))
-                })
+                }).collect()
             }
             _ => fail!("unexpected item")
         }
     };
 
-    do vec::map_zip(docs, attrs) |doc, attrs| {
+    do docs.iter().zip(attrs.iter()).transform |(doc, attrs)| {
         assert!(doc.name == attrs.first());
         let desc = attrs.second();
 
@@ -215,7 +214,7 @@ fn merge_method_attrs(
             desc: desc,
             .. copy *doc
         }
-    }
+    }.collect()
 }
 
 
index c2127eae6253588e7cfb0d79e1cfab14cabba420..d5d2b4ce6286cea90f1480af57b35880ad05be5d 100644 (file)
@@ -186,7 +186,7 @@ fn enumdoc_from_enum(
 fn variantdocs_from_variants(
     variants: ~[ast::variant]
 ) -> ~[doc::VariantDoc] {
-    vec::map(variants, variantdoc_from_variant)
+    variants.iter().transform(variantdoc_from_variant).collect()
 }
 
 fn variantdoc_from_variant(variant: &ast::variant) -> doc::VariantDoc {
@@ -203,7 +203,7 @@ fn traitdoc_from_trait(
 ) -> doc::TraitDoc {
     doc::TraitDoc {
         item: itemdoc,
-        methods: do vec::map(methods) |method| {
+        methods: do methods.iter().transform |method| {
             match copy *method {
               ast::required(ty_m) => {
                 doc::MethodDoc {
@@ -226,7 +226,7 @@ fn traitdoc_from_trait(
                 }
               }
             }
-        }
+        }.collect()
     }
 }
 
@@ -239,7 +239,7 @@ fn impldoc_from_impl(
         bounds_str: None,
         trait_types: ~[],
         self_ty: None,
-        methods: do vec::map(methods) |method| {
+        methods: do methods.iter().transform |method| {
             doc::MethodDoc {
                 name: to_str(method.ident),
                 brief: None,
@@ -248,7 +248,7 @@ fn impldoc_from_impl(
                 sig: None,
                 implementation: doc::Provided,
             }
-        }
+        }.collect()
     }
 }
 
index efb3e61e807fa6a5e2fc98fcea3d4dd768376ec5..6510384ef01dd8877aaa58274ab2b898b8e53d37 100644 (file)
@@ -13,8 +13,6 @@
 #[cfg(test)] use extract;
 #[cfg(test)] use parse;
 
-use std::vec;
-
 pub struct Fold<T> {
     ctxt: T,
     fold_doc: FoldDoc<T>,
@@ -155,7 +153,7 @@ pub fn default_par_fold<T:Clone>(ctxt: T) -> Fold<T> {
 
 pub fn default_seq_fold_doc<T>(fold: &Fold<T>, doc: doc::Doc) -> doc::Doc {
     doc::Doc {
-        pages: do vec::map(doc.pages) |page| {
+        pages: do doc.pages.iter().transform |page| {
             match copy *page {
               doc::CratePage(doc) => {
                 doc::CratePage((fold.fold_crate)(fold, doc))
@@ -164,7 +162,7 @@ pub fn default_seq_fold_doc<T>(fold: &Fold<T>, doc: doc::Doc) -> doc::Doc {
                 doc::ItemPage(fold_ItemTag(fold, doc))
               }
             }
-        },
+        }.collect(),
         .. doc
     }
 }
@@ -191,9 +189,9 @@ pub fn default_any_fold_mod<T:Clone>(
 ) -> doc::ModDoc {
     doc::ModDoc {
         item: (fold.fold_item)(fold, copy doc.item),
-        items: vec::map(doc.items, |ItemTag| {
+        items: doc.items.iter().transform(|ItemTag| {
             fold_ItemTag(fold, copy *ItemTag)
-        }),
+        }).collect(),
         .. doc
     }
 }
@@ -204,9 +202,9 @@ pub fn default_seq_fold_mod<T>(
 ) -> doc::ModDoc {
     doc::ModDoc {
         item: (fold.fold_item)(fold, copy doc.item),
-        items: vec::map(doc.items, |ItemTag| {
+        items: doc.items.iter().transform(|ItemTag| {
             fold_ItemTag(fold, copy *ItemTag)
-        }),
+        }).collect(),
         .. doc
     }
 }
@@ -217,9 +215,9 @@ pub fn default_par_fold_mod<T:Clone>(
 ) -> doc::ModDoc {
     doc::ModDoc {
         item: (fold.fold_item)(fold, copy doc.item),
-        items: vec::map(doc.items, |ItemTag| {
+        items: doc.items.iter().transform(|ItemTag| {
             fold_ItemTag(fold, copy *ItemTag)
-        }),
+        }).collect(),
         .. doc
     }
 }
@@ -230,9 +228,9 @@ pub fn default_any_fold_nmod<T:Clone>(
 ) -> doc::NmodDoc {
     doc::NmodDoc {
         item: (fold.fold_item)(fold, copy doc.item),
-        fns: vec::map(doc.fns, |FnDoc| {
+        fns: doc.fns.iter().transform(|FnDoc| {
             (fold.fold_fn)(fold, copy *FnDoc)
-        }),
+        }).collect(),
         .. doc
     }
 }
@@ -243,9 +241,9 @@ pub fn default_seq_fold_nmod<T>(
 ) -> doc::NmodDoc {
     doc::NmodDoc {
         item: (fold.fold_item)(fold, copy doc.item),
-        fns: vec::map(doc.fns, |FnDoc| {
+        fns: doc.fns.iter().transform(|FnDoc| {
             (fold.fold_fn)(fold, copy *FnDoc)
-        }),
+        }).collect(),
         .. doc
     }
 }
@@ -256,9 +254,9 @@ pub fn default_par_fold_nmod<T:Clone>(
 ) -> doc::NmodDoc {
     doc::NmodDoc {
         item: (fold.fold_item)(fold, copy doc.item),
-        fns: vec::map(doc.fns, |FnDoc| {
+        fns: doc.fns.iter().transform(|FnDoc| {
             (fold.fold_fn)(fold, copy *FnDoc)
-        }),
+        }).collect(),
         .. doc
     }
 }
index c3b02c91e749476d7a1c630b1f86a7ca2fe36ac7..e40bdb532da932e8fc228b9a6e5bbf910cee7c92 100644 (file)
@@ -20,7 +20,6 @@
 use fold;
 use pass::Pass;
 
-use std::vec;
 use syntax::ast;
 use syntax::print::pprust;
 use syntax::parse::token;
@@ -114,7 +113,7 @@ fn fold_enum(
     let srv = fold.ctxt.clone();
 
     doc::EnumDoc {
-        variants: do vec::map(doc.variants) |variant| {
+        variants: do doc.variants.iter().transform |variant| {
             let sig = {
                 let variant = copy *variant;
                 do astsrv::exec(srv.clone()) |ctxt| {
@@ -139,7 +138,7 @@ fn fold_enum(
                 sig: Some(sig),
                 .. copy *variant
             }
-        },
+        }.collect(),
         .. doc
     }
 }
@@ -159,12 +158,12 @@ fn merge_methods(
     item_id: doc::AstId,
     docs: ~[doc::MethodDoc]
 ) -> ~[doc::MethodDoc] {
-    do vec::map(docs) |doc| {
+    do docs.iter().transform |doc| {
         doc::MethodDoc {
             sig: get_method_sig(srv.clone(), item_id, copy doc.name),
             .. copy *doc
         }
-    }
+    }.collect()
 }
 
 fn get_method_sig(
index 40793ff1af7b16e4f1e8fbe962df8f7429338528..bdcad15f45c444fd9ad8bc70dbab1ec7fc869b6c 100644 (file)
@@ -1912,7 +1912,9 @@ fn check_read_ln(len : uint, s: &str, ivals: &[int]) {
                 if len <= ivals.len() {
                     assert_eq!(res.len(), len);
                 }
-                assert!(ivals.slice(0u, res.len()) == vec::map(res, |x| *x as int));
+                for ivals.iter().zip(res.iter()).advance |(iv, c)| {
+                    assert!(*iv == *c as int)
+                }
             }
         }
         let mut i = 0;
index 55eae8f8fae182d6726eb277eeaecce0dcdbbc40..77befbf19aa92f9afb5fe3dc5782bb5f37b6d60a 100644 (file)
@@ -85,8 +85,7 @@ pub trait IteratorUtil<A> {
 
     // FIXME: #5898: should be called map
     /// Creates a new iterator which will apply the specified function to each
-    /// element returned by the first, yielding the mapped element instead. This
-    /// similar to the `vec::map` function.
+    /// element returned by the first, yielding the mapped element instead.
     ///
     /// # Example
     ///
index fefd55c354158a19e3c68e2f2e511aa26005bbf4..4570254627833a795cd49eeb9d9a296f17e6ec6b 100644 (file)
@@ -14,6 +14,8 @@
 
 use kinds::Copy;
 use vec;
+use vec::ImmutableVector;
+use iterator::IteratorUtil;
 
 pub use self::inner::*;
 
@@ -96,7 +98,7 @@ fn zip(&self) -> ~[(A, B)] {
     fn map<C>(&self, f: &fn(a: &A, b: &B) -> C) -> ~[C] {
         match *self {
             (ref a, ref b) => {
-                vec::map_zip(*a, *b, f)
+                a.iter().zip(b.iter()).transform(|(aa, bb)| f(aa, bb)).collect()
             }
         }
     }
@@ -116,7 +118,7 @@ fn zip(&self) -> ~[(A, B)] {
     fn map<C>(&self, f: &fn(a: &A, b: &B) -> C) -> ~[C] {
         match *self {
             (ref a, ref b) => {
-                vec::map_zip(*a, *b, f)
+                a.iter().zip(b.iter()).transform(|(aa, bb)| f(aa, bb)).collect()
             }
         }
     }
index 976a67ef4227b769d987920107126f01248e8fbe..65f962c36ef8c312ad428b79e14b21f7831d0e05 100644 (file)
@@ -365,15 +365,6 @@ pub fn append_one<T>(lhs: ~[T], x: T) -> ~[T] {
 
 // Functional utilities
 
-/// Apply a function to each element of a vector and return the results
-pub fn map<T, U>(v: &[T], f: &fn(t: &T) -> U) -> ~[U] {
-    let mut result = with_capacity(v.len());
-    for v.iter().advance |elem| {
-        result.push(f(elem));
-    }
-    result
-}
-
 /// Consumes a vector, mapping it into a different vector. This function takes
 /// ownership of the supplied vector `v`, moving each element into the closure
 /// provided to generate a new element. The vector of new elements is then
@@ -388,16 +379,6 @@ pub fn map_consume<T, U>(v: ~[T], f: &fn(v: T) -> U) -> ~[U] {
     }
     result
 }
-
-/// Apply a function to each element of a vector and return the results
-pub fn mapi<T, U>(v: &[T], f: &fn(uint, t: &T) -> U) -> ~[U] {
-    let mut i = 0;
-    do map(v) |e| {
-        i += 1;
-        f(i - 1, e)
-    }
-}
-
 /**
  * Apply a function to each element of a vector and return a concatenation
  * of each result vector
@@ -408,23 +389,6 @@ pub fn flat_map<T, U>(v: &[T], f: &fn(t: &T) -> ~[U]) -> ~[U] {
     result
 }
 
-/**
- * Apply a function to each pair of elements and return the results.
- * Equivalent to `map(zip(v0, v1), f)`.
- */
-pub fn map_zip<T:Copy,U:Copy,V>(v0: &[T], v1: &[U],
-                                  f: &fn(t: &T, v: &U) -> V) -> ~[V] {
-    let v0_len = v0.len();
-    if v0_len != v1.len() { fail!(); }
-    let mut u: ~[V] = ~[];
-    let mut i = 0u;
-    while i < v0_len {
-        u.push(f(&v0[i], &v1[i]));
-        i += 1u;
-    }
-    u
-}
-
 pub fn filter_map<T, U>(
     v: ~[T],
     f: &fn(t: T) -> Option<U>) -> ~[U]
@@ -983,14 +947,13 @@ pub trait ImmutableVector<'self, T> {
     fn last(&self) -> &'self T;
     fn last_opt(&self) -> Option<&'self T>;
     fn rposition(&self, f: &fn(t: &T) -> bool) -> Option<uint>;
-    fn map<U>(&self, f: &fn(t: &T) -> U) -> ~[U];
-    fn mapi<U>(&self, f: &fn(uint, t: &T) -> U) -> ~[U];
-    fn map_r<U>(&self, f: &fn(x: &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;
 
     fn bsearch(&self, f: &fn(&T) -> Ordering) -> Option<uint>;
+
+    fn map<U>(&self, &fn(t: &T) -> U) -> ~[U];
 }
 
 /// Extension methods for vectors
@@ -1087,29 +1050,6 @@ fn rposition(&self, f: &fn(t: &T) -> bool) -> Option<uint> {
         None
     }
 
-    /// Apply a function to each element of a vector and return the results
-    #[inline]
-    fn map<U>(&self, f: &fn(t: &T) -> U) -> ~[U] { map(*self, f) }
-
-    /**
-     * Apply a function to the index and value of each element in the vector
-     * and return the results
-     */
-    fn mapi<U>(&self, f: &fn(uint, t: &T) -> U) -> ~[U] {
-        mapi(*self, f)
-    }
-
-    #[inline]
-    fn map_r<U>(&self, f: &fn(x: &T) -> U) -> ~[U] {
-        let mut r = ~[];
-        let mut i = 0;
-        while i < self.len() {
-            r.push(f(&self[i]));
-            i += 1;
-        }
-        r
-    }
-
     /**
      * Apply a function to each element of a vector and return a concatenation
      * of each result vector
@@ -1165,6 +1105,13 @@ fn bsearch(&self, f: &fn(&T) -> Ordering) -> Option<uint> {
         }
         return None;
     }
+
+    /// Deprecated, use iterators where possible
+    /// (`self.iter().transform(f)`). Apply a function to each element
+    /// of a vector and return the results.
+    fn map<U>(&self, f: &fn(t: &T) -> U) -> ~[U] {
+        self.iter().transform(f).collect()
+    }
 }
 
 #[allow(missing_doc)]
@@ -2101,7 +2048,7 @@ pub fn copy_memory(dst: &mut [u8], src: &[u8], count: uint) {
 impl<A:Clone> Clone for ~[A] {
     #[inline]
     fn clone(&self) -> ~[A] {
-        self.map(|item| item.clone())
+        self.iter().transform(|item| item.clone()).collect()
     }
 }
 
@@ -2648,16 +2595,16 @@ fn test_dedup_shared() {
     #[test]
     fn test_map() {
         // Test on-stack map.
-        let mut v = ~[1u, 2u, 3u];
-        let mut w = map(v, square_ref);
+        let v = &[1u, 2u, 3u];
+        let mut w = v.map(square_ref);
         assert_eq!(w.len(), 3u);
         assert_eq!(w[0], 1u);
         assert_eq!(w[1], 4u);
         assert_eq!(w[2], 9u);
 
         // Test on-heap map.
-        v = ~[1u, 2u, 3u, 4u, 5u];
-        w = map(v, square_ref);
+        let v = ~[1u, 2u, 3u, 4u, 5u];
+        w = v.map(square_ref);
         assert_eq!(w.len(), 5u);
         assert_eq!(w[0], 1u);
         assert_eq!(w[1], 4u);
@@ -2666,17 +2613,6 @@ fn test_map() {
         assert_eq!(w[4], 25u);
     }
 
-    #[test]
-    fn test_map_zip() {
-        fn times(x: &int, y: &int) -> int { *x * *y }
-        let f = times;
-        let v0 = ~[1, 2, 3, 4, 5];
-        let v1 = ~[5, 4, 3, 2, 1];
-        let u = map_zip::<int, int, int>(v0, v1, f);
-        let mut i = 0;
-        while i < 5 { assert!(v0[i] * v1[i] == u[i]); i += 1; }
-    }
-
     #[test]
     fn test_filter_mapped() {
         // Test on-stack filter-map.
@@ -2708,7 +2644,7 @@ fn halve_for_sure(i: &int) -> int { *i / 2 }
         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) ==
-                     map(all_even, halve_for_sure));
+                     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);
@@ -2746,7 +2682,7 @@ fn halve_for_sure(i: &int) -> int { *i / 2 }
         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) ==
-                     map(all_even0, halve_for_sure));
+                     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);
@@ -3278,7 +3214,7 @@ fn test_grow_fn_fail() {
     fn test_map_fail() {
         let v = [(~0, @0), (~0, @0), (~0, @0), (~0, @0)];
         let mut i = 0;
-        do map(v) |_elt| {
+        do v.map |_elt| {
             if i == 2 {
                 fail!()
             }
@@ -3302,44 +3238,13 @@ fn test_map_consume_fail() {
         };
     }
 
-    #[test]
-    #[ignore(windows)]
-    #[should_fail]
-    fn test_mapi_fail() {
-        let v = [(~0, @0), (~0, @0), (~0, @0), (~0, @0)];
-        let mut i = 0;
-        do mapi(v) |_i, _elt| {
-            if i == 2 {
-                fail!()
-            }
-            i += 0;
-            ~[(~0, @0)]
-        };
-    }
-
     #[test]
     #[ignore(windows)]
     #[should_fail]
     fn test_flat_map_fail() {
         let v = [(~0, @0), (~0, @0), (~0, @0), (~0, @0)];
         let mut i = 0;
-        do map(v) |_elt| {
-            if i == 2 {
-                fail!()
-            }
-            i += 0;
-            ~[(~0, @0)]
-        };
-    }
-
-    #[test]
-    #[ignore(windows)]
-    #[should_fail]
-    #[allow(non_implicitly_copyable_typarams)]
-    fn test_map_zip_fail() {
-        let v = [(~0, @0), (~0, @0), (~0, @0), (~0, @0)];
-        let mut i = 0;
-        do map_zip(v, v) |_elt1, _elt2| {
+        do flat_map(v) |_elt| {
             if i == 2 {
                 fail!()
             }
index ee7c7180f8db2d3e5ca1a8c3b4706eca3d7d19e9..529d5bfe70b49f8a6c975024e209ba9433eb0b8a 100644 (file)
@@ -814,7 +814,7 @@ mod test {
     // convert a list of uints to an @[ident]
     // (ignores the interner completely)
     fn uints_to_idents (uints: &~[uint]) -> @~[ident] {
-        @uints.map(|u|{ ident {name:*u, ctxt: empty_ctxt} })
+        @uints.map(|u| ident {name:*u, ctxt: empty_ctxt})
     }
 
     fn id (u : uint, s: SyntaxContext) -> ident {
index 77dbd96255d12b19313160daf533774e34cad3ed..405f9e3438beb1b23706c7089107577c1bcb0ba8 100644 (file)
@@ -91,9 +91,9 @@ fn decodable_substructure(cx: @ExtCtxt, span: span,
                     }
                 }
                 Right(ref fields) => {
-                    let fields = do fields.mapi |i, f| {
+                    let fields = do fields.iter().enumerate().transform |(i, f)| {
                         cx.field_imm(span, *f, getarg(cx.str_of(*f), i))
-                    };
+                    }.collect();
                     cx.expr_struct_ident(span, substr.type_ident, fields)
                 }
             };
@@ -133,9 +133,9 @@ fn decodable_substructure(cx: @ExtCtxt, span: span,
                         }
                     }
                     Right(ref fields) => {
-                        let fields = do fields.mapi |i, f| {
+                        let fields = do fields.iter().enumerate().transform |(i, f)| {
                             cx.field_imm(span, *f, getarg(i))
-                        };
+                        }.collect();
                         cx.expr_struct_ident(span, name, fields)
                     }
                 };
index 10d9f878bc45187234357d598d4ffbbbf94ce662..0e4fc9d96fa875cad58d3e626875b6aea3e6915e 100644 (file)
@@ -591,14 +591,14 @@ fn expand_struct_method_body(&self,
         // transpose raw_fields
         let fields = match raw_fields {
             [self_arg, .. rest] => {
-                do self_arg.mapi |i, &(opt_id, field)| {
+                do self_arg.iter().enumerate().transform |(i, &(opt_id, field))| {
                     let other_fields = do rest.map |l| {
                         match &l[i] {
                             &(_, ex) => ex
                         }
                     };
                     (opt_id, field, other_fields)
-                }
+                }.collect()
             }
             [] => { cx.span_bug(span, "No self arguments to non-static \
                                        method in generic `deriving`") }
@@ -745,10 +745,11 @@ fn build_enum_match(&self,
                         }
                     }
                     let field_tuples =
-                        do vec::map_zip(*self_vec,
-                                        enum_matching_fields) |&(id, self_f), &other| {
+                        do self_vec.iter()
+                           .zip(enum_matching_fields.iter())
+                           .transform |(&(id, self_f), &other)| {
                         (id, self_f, other)
-                    };
+                    }.collect();
                     substructure = EnumMatching(variant_index, variant, field_tuples);
                 }
                 None => {
index 19aa29a62a9c02510c653d14184e19f52a76a194..cc2050d9bd7a0a31bc4ad4c2a5f23258af7de010 100644 (file)
@@ -91,7 +91,7 @@ fn rand_substructure(cx: @ExtCtxt, span: span, substr: &Substructure) -> @expr {
             let rand_variant = cx.expr_binary(span, ast::rem,
                                               rv_call, variant_count);
 
-            let mut arms = do variants.mapi |i, id_sum| {
+            let mut arms = do variants.iter().enumerate().transform |(i, id_sum)| {
                 let i_expr = cx.expr_uint(span, i);
                 let pat = cx.pat_lit(span, i_expr);
 
@@ -102,7 +102,7 @@ fn rand_substructure(cx: @ExtCtxt, span: span, substr: &Substructure) -> @expr {
                                rand_thing(cx, span, ident, summary, || rand_call()))
                     }
                 }
-            };
+            }.collect::<~[ast::arm]>();
 
             // _ => {} at the end. Should never occur
             arms.push(cx.arm_unreachable(span));
index 3044cd50b344c4e11591d99dbf2b46087562a616..0e24725ea990ce86e109e2c1a2f8c186c7280fe7 100644 (file)
@@ -54,8 +54,9 @@ fn gen_send(&mut self, cx: @ExtCtxt, try: bool) -> @ast::item {
             let next = this.proto.get_state(next_state.state);
             assert!(next_state.tys.len() ==
                 next.generics.ty_params.len());
-            let arg_names = tys.mapi(|i, _ty| cx.ident_of(~"x_"+i.to_str()));
-            let args_ast = vec::map_zip(arg_names, *tys, |n, t| cx.arg(span, *n, *t));
+            let arg_names = vec::from_fn(tys.len(), |i| cx.ident_of("x_"+i.to_str()));
+            let args_ast: ~[ast::arg] = arg_names.iter().zip(tys.iter())
+                .transform(|(n, t)| cx.arg(span, *n, *t)).collect();
 
             let pipe_ty = cx.ty_path(
                 path(~[this.data_name()], span)
@@ -133,11 +134,10 @@ fn gen_send(&mut self, cx: @ExtCtxt, try: bool) -> @ast::item {
 
             message(ref _id, span, ref tys, this, None) => {
                 debug!("pipec: no next state");
-                let arg_names = tys.mapi(|i, _ty| (~"x_" + i.to_str()));
+                let arg_names = vec::from_fn(tys.len(), |i| "x_" + i.to_str());
 
-                let args_ast = do vec::map_zip(arg_names, *tys) |n, t| {
-                    cx.arg(span, cx.ident_of(*n), *t)
-                };
+                let args_ast: ~[ast::arg] = arg_names.iter().zip(tys.iter())
+                    .transform(|(n, t)| cx.arg(span, cx.ident_of(*n), *t)).collect();
 
                 let args_ast = vec::append(
                     ~[cx.arg(span,
index 71dc82be414362fd4b66b4923074777ef30a10cb..f6325c2eb2c123819e826be1997dde393edcded9 100644 (file)
@@ -21,7 +21,6 @@
 
 use std::io;
 use std::result;
-use std::vec;
 
 // These macros all relate to the file system; they either return
 // the column/row/filename of the expression, or they include
@@ -106,9 +105,7 @@ pub fn expand_include_bin(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree])
     let file = get_single_str_from_tts(cx, sp, tts, "include_bin!");
     match io::read_whole_file(&res_rel_file(cx, sp, &Path(file))) {
       result::Ok(src) => {
-        let u8_exprs = vec::map(src, |char| {
-            cx.expr_u8(sp, *char)
-        });
+        let u8_exprs: ~[@ast::expr] = src.iter().transform(|char| cx.expr_u8(sp, *char)).collect();
         base::MRExpr(cx.expr_vec(sp, u8_exprs))
       }
       result::Err(ref e) => {
index 7c69bdd01c8152334f6dcb558154d4074e4bfbc6..cddba3583734d9e1003b4eba8070e6d7224f7872 100644 (file)
@@ -326,8 +326,7 @@ pub fn parse(
                         cur_eis.push(new_ei);
                     }
 
-                    let matches = vec::map(ei.matches, // fresh, same size:
-                                           |_m| ~[]);
+                    let matches = vec::from_elem(ei.matches.len(), ~[]);
                     let ei_t = ei;
                     cur_eis.push(~MatcherPos {
                         elts: copy *matchers,
index 2fc111da453cf1023a5059dc470c2ce2186db59d..4e1451239962f5937fe1069928f5f63ee4e11201 100644 (file)
@@ -699,7 +699,7 @@ fn fold_opt_bounds(b: &Option<OptVec<TyParamBound>>, fld: @ast_fold)
 // ...nor do modules
 pub fn noop_fold_mod(m: &_mod, fld: @ast_fold) -> _mod {
     ast::_mod {
-        view_items: vec::map(m.view_items, |x| fld.fold_view_item(*x)),
+        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)),
     }
 }
@@ -708,8 +708,8 @@ fn noop_fold_foreign_mod(nm: &foreign_mod, fld: @ast_fold) -> foreign_mod {
     ast::foreign_mod {
         sort: nm.sort,
         abis: nm.abis,
-        view_items: vec::map(nm.view_items, |x| fld.fold_view_item(*x)),
-        items: vec::map(nm.items, |x| fld.fold_foreign_item(*x)),
+        view_items: nm.view_items.iter().transform(|x| fld.fold_view_item(*x)).collect(),
+        items: nm.items.iter().transform(|x| fld.fold_foreign_item(*x)).collect(),
     }
 }
 
@@ -728,8 +728,8 @@ fn fold_variant_arg_(va: variant_arg, fld: @ast_fold) -> variant_arg {
         }
         struct_variant_kind(struct_def) => {
             kind = struct_variant_kind(@ast::struct_def {
-                fields: vec::map(struct_def.fields,
-                                 |f| fld.fold_struct_field(*f)),
+                fields: struct_def.fields.iter()
+                    .transform(|f| fld.fold_struct_field(*f)).collect(),
                 ctor_id: struct_def.ctor_id.map(|c| fld.new_id(*c))
             })
         }
@@ -824,8 +824,7 @@ fn fold_view_item(@self, x: @view_item) ->
        @view_item {
         @ast::view_item {
             node: (self.fold_view_item)(&x.node, self as @ast_fold),
-            attrs: vec::map(x.attrs, |a|
-                  fold_attribute_(*a, self as @ast_fold)),
+            attrs: x.attrs.iter().transform(|a| fold_attribute_(*a, self as @ast_fold)).collect(),
             vis: x.vis,
             span: (self.new_span)(x.span),
         }
index eeff4b71c0d2f69553842b76bcd454af07ae8b79..bc5efc5fca1f0ad26156a01c5e9f33d513a8fe23 100644 (file)
@@ -191,13 +191,13 @@ fn is_gray(c: &color) -> bool {
         // Do the BFS.
         info!("PBFS iteration %?", i);
         i += 1;
-        colors = do colors.mapi() |i, c| {
+        colors = do colors.iter().enumerate().transform |(i, c)| {
             let c : color = *c;
             match c {
               white => {
                 let i = i as node_id;
 
-                let neighbors = copy graph[i];
+                let neighbors = &graph[i];
 
                 let mut color = white;
 
@@ -214,17 +214,17 @@ fn is_gray(c: &color) -> bool {
               gray(parent) => { black(parent) }
               black(parent) => { black(parent) }
             }
-        }
+        }.collect()
     }
 
     // Convert the results.
-    do vec::map(colors) |c| {
+    do colors.iter().transform |c| {
         match *c {
           white => { -1i64 }
           black(parent) => { parent }
           _ => { fail!("Found remaining gray nodes in BFS") }
         }
-    }
+    }.collect()
 }
 
 /// A parallel version of the bfs function.
index 49a3a3ec5d7d39801df461ea4595ae7816956573..deb2d4b300bc625114bae1df65fe3aaef9eedbf8 100644 (file)
@@ -152,7 +152,7 @@ fn rendezvous(nn: uint, set: ~[color]) {
 
     // these channels will allow us to talk to each creature by 'name'/index
     let to_creature: ~[Chan<Option<CreatureInfo>>] =
-        vec::mapi(set, |ii, col| {
+        set.iter().enumerate().transform(|(ii, col)| {
             // create each creature as a listener with a port, and
             // give us a channel to talk to each
             let ii = ii;
@@ -166,7 +166,7 @@ fn rendezvous(nn: uint, set: ~[color]) {
                          to_rendezvous_log.clone());
             }
             to_creature
-        });
+        }).collect();
 
     let mut creatures_met = 0;
 
index d26fe80e8a124f4c815a4ce73c83828dfe5783e0..974cdb0a0ef6320c7e6782e0ea74c9884fb32b3d 100644 (file)
@@ -8,7 +8,7 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-// xfail-pretty (extra blank line is inserted in vec::mapi call)
+// xfail-pretty the `let to_child` line gets an extra newline
 // multi tasking k-nucleotide
 
 extern mod extra;
@@ -163,14 +163,13 @@ fn main() {
 
 
 
-   // initialize each sequence sorter
-   let sizes = ~[1,2,3,4,6,12,18];
-    let streams = vec::map(sizes, |_sz| Some(stream()));
-    let mut streams = streams;
+    // initialize each sequence sorter
+    let sizes = ~[1u,2,3,4,6,12,18];
+    let mut streams = vec::from_fn(sizes.len(), |_| Some(stream::<~str>()));
     let mut from_child = ~[];
-    let to_child   = vec::mapi(sizes, |ii, sz| {
+    let to_child   = do sizes.iter().zip(streams.mut_iter()).transform |(sz, stream_ref)| {
         let sz = *sz;
-        let stream = util::replace(&mut streams[ii], None);
+        let stream = util::replace(stream_ref, None);
         let (from_child_, to_parent_) = stream.unwrap();
 
         from_child.push(from_child_);
@@ -182,7 +181,7 @@ fn main() {
         };
 
         to_child
-    });
+    }.collect::<~[Chan<~[u8]>]>();
 
 
    // latch stores true after we've started
index 4a748cc56700a33166c9d7b6c54e7673c959bbe9..e61de0ac11f4c45ad1e490a8bbff0d97b441c50b 100644 (file)
@@ -30,7 +30,7 @@
 
 // Make sure this import is warned about when at least one of its imported names
 // is unused
-use std::vec::{filter, map};   //~ ERROR unused import
+use std::vec::{filter, from_elem};   //~ ERROR unused import
 
 mod foo {
     pub struct Point{x: int, y: int}
@@ -58,7 +58,5 @@ fn main() {
     let a = 3;
     ignore(a);
     io::stdout().write_str("a");
-    let _a = do map([2]) |&x| {
-      x + 2
-    };
+    let _a = from_elem(0, 0);
 }
index ff5d0e9f05c657d341fdfa964689d517d77016c9..8ea2a88fa09a793319e26f9b25b6742f41d1413f 100644 (file)
@@ -28,7 +28,7 @@ pub fn main() {
     assert!(any_negative);
 
     // Higher precedence than unary operations:
-    let abs_v = do vec::map(v) |e| { e.abs() };
+    let abs_v = do v.iter().transform |e| { e.abs() }.collect::<~[float]>();
     assert!(do abs_v.iter().all |e| { e.is_positive() });
     assert!(!do abs_v.iter().any_ |e| { e.is_negative() });
 
diff --git a/src/test/run-pass/block-vec-map_zip.rs b/src/test/run-pass/block-vec-map_zip.rs
deleted file mode 100644 (file)
index 739dbab..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-use std::vec;
-
-pub fn main() {
-    let v =
-        vec::map_zip(~[1, 2, 3, 4, 5],
-                  ~[true, false, false, true, true],
-                  |i, b| if *b { -(*i) } else { *i } );
-    error!(v.clone());
-    assert_eq!(v, ~[-1, 2, 3, -4, -5]);
-}
index 4029bd18338c33d28c13a1882ac3faaa559dc2b3..3e4cfdc105cadb966debf83ebfc0cae52902e073 100644 (file)
@@ -15,7 +15,9 @@
 extern mod std;
 
 use std::str::StrVector;
-use std::{int, vec};
+use std::vec::ImmutableVector;
+use std::iterator::IteratorUtil;
+use std::int;
 
 trait to_str {
     fn to_str(&self) -> ~str;
@@ -27,7 +29,7 @@ fn to_str(&self) -> ~str { int::to_str(*self) }
 
 impl<T:to_str> to_str for ~[T] {
     fn to_str(&self) -> ~str {
-        ~"[" + vec::map(*self, |e| e.to_str()).connect(", ") + "]"
+        fmt!("[%s]", self.iter().transform(|e| e.to_str()).collect::<~[~str]>().connect(", "))
     }
 }