@@ -69,8 +69,7 @@ pub fn rights<T, U: Copy>(eithers: &[Either<T, U>]) -> ~[U] {
69
69
}
70
70
}
71
71
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 > ] )
74
73
-> ( ~[ T ] , ~[ U ] ) {
75
74
/*!
76
75
* 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>])
81
80
82
81
let mut lefts: ~[ T ] = ~[ ] ;
83
82
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)
88
87
}
89
88
}
90
89
return ( move lefts, move rights) ;
91
90
}
92
91
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 > {
95
93
//! Flips between left and right of a given either
96
94
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)
100
98
}
101
99
}
102
100
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 > )
105
102
-> Result < U , T > {
106
103
/*!
107
104
* Converts either::t to a result::t
@@ -110,9 +107,9 @@ pub pure fn to_result<T: Copy, U: Copy>(eith: &Either<T, U>)
110
107
* an ok result, and the "left" choice a fail
111
108
*/
112
109
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)
116
113
}
117
114
}
118
115
@@ -128,7 +125,6 @@ pub pure fn is_right<T, U>(eith: &Either<T, U>) -> bool {
128
125
match * eith { Right ( _) => true , _ => false }
129
126
}
130
127
131
- // tjc: fix the next two after a snapshot
132
128
pub pure fn unwrap_left < T , U > ( eith : Either < T , U > ) -> T {
133
129
//! Retrieves the value in the left branch. Fails if the either is Right.
134
130
0 commit comments