diff --git a/src/libcore/either.rs b/src/libcore/either.rs index 866232dc49c..b2c70916a00 100644 --- a/src/libcore/either.rs +++ b/src/libcore/either.rs @@ -69,8 +69,7 @@ pub fn rights(eithers: &[Either]) -> ~[U] { } } -// XXX bad copies. take arg by val -pub fn partition(eithers: &[Either]) +pub fn partition(eithers: ~[Either]) -> (~[T], ~[U]) { /*! * Extracts from a vector of either all the left values and right values @@ -81,27 +80,25 @@ pub fn partition(eithers: &[Either]) let mut lefts: ~[T] = ~[]; let mut rights: ~[U] = ~[]; - for vec::each(eithers) |elt| { - match *elt { - Left(copy l) => lefts.push(l), - Right(copy r) => rights.push(r) + do vec::consume(eithers) |_i, elt| { + match elt { + Left(l) => lefts.push(l), + Right(r) => rights.push(r) } } return (move lefts, move rights); } -// XXX bad copies -pub pure fn flip(eith: &Either) -> Either { +pub pure fn flip(eith: Either) -> Either { //! Flips between left and right of a given either - match *eith { - Right(copy r) => Left(r), - Left(copy l) => Right(l) + match eith { + Right(r) => Left(r), + Left(l) => Right(l) } } -// XXX bad copies -pub pure fn to_result(eith: &Either) +pub pure fn to_result(eith: Either) -> Result { /*! * Converts either::t to a result::t @@ -110,9 +107,9 @@ pub pure fn to_result(eith: &Either) * an ok result, and the "left" choice a fail */ - match *eith { - Right(copy r) => result::Ok(r), - Left(copy l) => result::Err(l) + match eith { + Right(r) => result::Ok(r), + Left(l) => result::Err(l) } } @@ -128,7 +125,6 @@ pub pure fn is_right(eith: &Either) -> bool { match *eith { Right(_) => true, _ => false } } -// tjc: fix the next two after a snapshot pub pure fn unwrap_left(eith: Either) -> T { //! Retrieves the value in the left branch. Fails if the either is Right.