Skip to content

Commit 2f5cb18

Browse files
committed
---
yaml --- r: 39671 b: refs/heads/incoming c: 4d8cc3f h: refs/heads/master i: 39669: 19ba4b1 39667: b81980f 39663: 82d0870 v: v3
1 parent ab96e00 commit 2f5cb18

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
@@ -6,7 +6,7 @@ refs/heads/try: 3d5418789064fdb463e872a4e651af1c628a3650
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: a810c03263670238bccd64cabb12a23a46e3a278
9-
refs/heads/incoming: 62f6f46072614d81b53c5487358c8589c91c7f95
9+
refs/heads/incoming: 4d8cc3f0036a5060bc7044892d891fb81afa00f7
1010
refs/heads/dist-snap: 22efa39382d41b084fde1719df7ae8ce5697d8c9
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/incoming/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)