Skip to content

Commit e0b279b

Browse files
committed
---
yaml --- r: 34394 b: refs/heads/snap-stage3 c: 4d8cc3f h: refs/heads/master v: v3
1 parent b970561 commit e0b279b

File tree

2 files changed

+14
-18
lines changed

2 files changed

+14
-18
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: cd6f24f9d14ac90d167386a56e7a6ac1f0318195
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 62f6f46072614d81b53c5487358c8589c91c7f95
4+
refs/heads/snap-stage3: 4d8cc3f0036a5060bc7044892d891fb81afa00f7
55
refs/heads/try: d324a424d8f84b1eb049b12cf34182bda91b0024
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/src/libcore/either.rs

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -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
132128
pub 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

Comments
 (0)