Skip to content

Commit 6277046

Browse files
committed
Add either::unwrap_{left,right}
1 parent 4cfb92f commit 6277046

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/libcore/either.rs

+16
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,22 @@ pure fn is_right<T, U>(eith: &Either<T, U>) -> bool {
109109
match *eith { Right(_) => true, _ => false }
110110
}
111111

112+
pure fn unwrap_left<T,U>(+eith: Either<T,U>) -> T {
113+
//! Retrieves the value in the left branch. Fails if the either is Right.
114+
115+
match move eith {
116+
Left(move x) => x, Right(_) => fail ~"either::unwrap_left Right"
117+
}
118+
}
119+
120+
pure fn unwrap_right<T,U>(+eith: Either<T,U>) -> U {
121+
//! Retrieves the value in the right branch. Fails if the either is Left.
122+
123+
match move eith {
124+
Right(move x) => x, Left(_) => fail ~"either::unwrap_right Left"
125+
}
126+
}
127+
112128
#[test]
113129
fn test_either_left() {
114130
let val = Left(10);

0 commit comments

Comments
 (0)