Skip to content

Rename vec::mod2 to vec::mod_zip #6057

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/libcore/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ pub fn map_vec2<S,T,U:Copy,V:Copy>(ss: &[S], ts: &[T],

/**
* Applies op to the pairwise elements from `ss` and `ts`, aborting on
* error. This could be implemented using `map2()` but it is more efficient
* error. This could be implemented using `map_zip()` but it is more efficient
* on its own as no result vector is built.
*/
#[inline(always)]
Expand Down
4 changes: 2 additions & 2 deletions src/libcore/tuple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ impl<'self,A:Copy,B:Copy> ExtendedTupleOps<A,B> for (&'self [A], &'self [B]) {
fn map<C>(&self, f: &fn(a: &A, b: &B) -> C) -> ~[C] {
match *self {
(ref a, ref b) => {
vec::map2(*a, *b, f)
vec::map_zip(*a, *b, f)
}
}
}
Expand All @@ -144,7 +144,7 @@ impl<A:Copy,B:Copy> ExtendedTupleOps<A,B> for (~[A], ~[B]) {
fn map<C>(&self, f: &fn(a: &A, b: &B) -> C) -> ~[C] {
match *self {
(ref a, ref b) => {
vec::map2(*a, *b, f)
vec::map_zip(*a, *b, f)
}
}
}
Expand Down
15 changes: 9 additions & 6 deletions src/libcore/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -847,8 +847,11 @@ 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
pub fn map2<T:Copy,U:Copy,V>(v0: &[T], v1: &[U],
/**
* 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 = len(v0);
if v0_len != len(v1) { fail!(); }
Expand Down Expand Up @@ -3396,12 +3399,12 @@ mod tests {
}

#[test]
fn test_map2() {
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 = map2::<int, int, int>(v0, v1, f);
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; }
}
Expand Down Expand Up @@ -4335,10 +4338,10 @@ mod tests {
#[ignore(windows)]
#[should_fail]
#[allow(non_implicitly_copyable_typarams)]
fn test_map2_fail() {
fn test_map_zip_fail() {
let v = [(~0, @0), (~0, @0), (~0, @0), (~0, @0)];
let mut i = 0;
do map2(v, v) |_elt1, _elt2| {
do map_zip(v, v) |_elt1, _elt2| {
if i == 2 {
fail!()
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/trans/monomorphize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ pub fn make_mono_id(ccx: @CrateContext,
Some(vts) => {
let item_ty = ty::lookup_item_type(ccx.tcx, item);
let mut i = 0;
vec::map2(*item_ty.generics.type_param_defs, substs, |type_param_def, subst| {
vec::map_zip(*item_ty.generics.type_param_defs, substs, |type_param_def, subst| {
let mut v = ~[];
for type_param_def.bounds.each |bound| {
match *bound {
Expand All @@ -376,7 +376,7 @@ pub fn make_mono_id(ccx: @CrateContext,
};
let param_ids = match param_uses {
Some(ref uses) => {
vec::map2(precise_param_ids, **uses, |id, uses| {
vec::map_zip(precise_param_ids, **uses, |id, uses| {
if ccx.sess.no_monomorphic_collapse() {
match copy *id {
(a, b) => mono_precise(a, b)
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/attr_pass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ fn merge_method_attrs(
}
};

do vec::map2(docs, attrs) |doc, attrs| {
do vec::map_zip(docs, attrs) |doc, attrs| {
assert!(doc.name == attrs.first());
let desc = attrs.second();

Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/ext/deriving/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ impl<'self> MethodDef<'self> {
}
}
let field_tuples =
do vec::map2(*self_vec,
do vec::map_zip(*self_vec,
enum_matching_fields) |&(id, self_f), &other| {
(id, self_f, other)
};
Expand Down
4 changes: 2 additions & 2 deletions src/libsyntax/ext/pipes/pipec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl gen_send for message {
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::map2(arg_names, *tys, |n, t| cx.arg(*n, *t));
let args_ast = vec::map_zip(arg_names, *tys, |n, t| cx.arg(*n, *t));

let pipe_ty = cx.ty_path_ast_builder(
path(~[this.data_name()], span)
Expand Down Expand Up @@ -135,7 +135,7 @@ impl gen_send for message {
debug!("pipec: no next state");
let arg_names = tys.mapi(|i, _ty| (~"x_" + i.to_str()));

let args_ast = do vec::map2(arg_names, *tys) |n, t| {
let args_ast = do vec::map_zip(arg_names, *tys) |n, t| {
cx.arg(cx.ident_of(*n), *t)
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ extern mod std;

pub fn main() {
let v =
vec::map2(~[1, 2, 3, 4, 5],
vec::map_zip(~[1, 2, 3, 4, 5],
~[true, false, false, true, true],
|i, b| if *b { -(*i) } else { *i } );
error!(v.clone());
Expand Down