@@ -69,8 +69,7 @@ pub fn rights<T, U: Copy>(eithers: &[Either<T, U>]) -> ~[U] {
6969 }
7070}
7171
72- // XXX bad copies. take arg by val
73- pub fn partition < T : Copy , U : Copy > ( eithers : & [ Either < T , U > ] )
72+ pub fn partition< T , U > ( eithers : ~[ Either < T , U > ] )
7473 -> ( ~[ T ] , ~[ U ] ) {
7574 /*!
7675 * Extracts from a vector of either all the left values and right values
@@ -81,27 +80,25 @@ pub fn partition<T: Copy, U: Copy>(eithers: &[Either<T, U>])
8180
8281 let mut lefts: ~[ T ] = ~[ ] ;
8382 let mut rights: ~[ U ] = ~[ ] ;
84- for vec:: each ( eithers) |elt| {
85- match * elt {
86- Left ( copy l) => lefts. push ( l) ,
87- Right ( copy r) => rights. push ( r)
83+ do vec:: consume ( eithers) |_i , elt| {
84+ match elt {
85+ Left ( l) => lefts. push ( l) ,
86+ Right ( r) => rights. push ( r)
8887 }
8988 }
9089 return ( move lefts, move rights) ;
9190}
9291
93- // XXX bad copies
94- pub pure fn flip < T : Copy , U : Copy > ( eith : & Either < T , U > ) -> Either < U , T > {
92+ pub pure fn flip < T , U > ( eith : Either < T , U > ) -> Either < U , T > {
9593 //! Flips between left and right of a given either
9694
97- match * eith {
98- Right ( copy r) => Left ( r) ,
99- Left ( copy l) => Right ( l)
95+ match eith {
96+ Right ( r) => Left ( r) ,
97+ Left ( l) => Right ( l)
10098 }
10199}
102100
103- // XXX bad copies
104- pub pure fn to_result < T : Copy , U : Copy > ( eith : & Either < T , U > )
101+ pub pure fn to_result < T , U > ( eith : Either < T , U > )
105102 -> Result < U , T > {
106103 /*!
107104 * Converts either::t to a result::t
@@ -110,9 +107,9 @@ pub pure fn to_result<T: Copy, U: Copy>(eith: &Either<T, U>)
110107 * an ok result, and the "left" choice a fail
111108 */
112109
113- match * eith {
114- Right ( copy r) => result:: Ok ( r) ,
115- Left ( copy l) => result:: Err ( l)
110+ match eith {
111+ Right ( r) => result:: Ok ( r) ,
112+ Left ( l) => result:: Err ( l)
116113 }
117114}
118115
@@ -128,7 +125,6 @@ pub pure fn is_right<T, U>(eith: &Either<T, U>) -> bool {
128125 match * eith { Right ( _) => true , _ => false }
129126}
130127
131- // tjc: fix the next two after a snapshot
132128pub pure fn unwrap_left < T , U > ( eith : Either < T , U > ) -> T {
133129 //! Retrieves the value in the left branch. Fails if the either is Right.
134130
0 commit comments