Skip to content

Commit 31a1d4d

Browse files
committed
---
yaml --- r: 22585 b: refs/heads/master c: e57745b h: refs/heads/master i: 22583: 0273c9e v: v3
1 parent 485a133 commit 31a1d4d

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 06c42b77d39ff0fa2e04b46aa7bc81bef0c1cfac
2+
refs/heads/master: e57745b48c6a032da10d497e2bee6c2b2a11637b
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: cd6f24f9d14ac90d167386a56e7a6ac1f0318195
55
refs/heads/try: ffbe0e0e00374358b789b0037bcb3a577cd218be

trunk/src/libcore/option.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,20 @@ pure fn expect<T: copy>(opt: option<T>, reason: ~str) -> T {
3737
alt opt { some(x) { x } none { fail reason; } }
3838
}
3939

40-
pure fn map<T, U: copy>(opt: option<T>, f: fn(T) -> U) -> option<U> {
40+
pure fn map<T, U>(opt: option<T>, f: fn(T) -> U) -> option<U> {
4141
//! Maps a `some` value from one type to another
4242
4343
alt opt { some(x) { some(f(x)) } none { none } }
4444
}
4545

46+
pure fn map_consume<T, U>(-opt: option<T>, f: fn(-T) -> U) -> option<U> {
47+
/*!
48+
* As `map`, but consumes the option and gives `f` ownership to avoid
49+
* copying.
50+
*/
51+
if opt.is_some() { some(f(option::unwrap(opt))) } else { none }
52+
}
53+
4654
pure fn chain<T, U>(opt: option<T>, f: fn(T) -> option<U>) -> option<U> {
4755
/*!
4856
* Update an optional value by optionally running its content through a
@@ -128,7 +136,7 @@ impl extensions<T> for option<T> {
128136
/// Returns true if the option contains some value
129137
pure fn is_some() -> bool { is_some(self) }
130138
/// Maps a `some` value from one type to another
131-
pure fn map<U:copy>(f: fn(T) -> U) -> option<U> { map(self, f) }
139+
pure fn map<U>(f: fn(T) -> U) -> option<U> { map(self, f) }
132140
}
133141

134142
impl extensions<T: copy> for option<T> {

0 commit comments

Comments
 (0)