@@ -37,12 +37,20 @@ pure fn expect<T: copy>(opt: option<T>, reason: ~str) -> T {
37
37
alt opt { some( x) { x } none { fail reason; } }
38
38
}
39
39
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 > {
41
41
//! Maps a `some` value from one type to another
42
42
43
43
alt opt { some( x) { some ( f ( x) ) } none { none } }
44
44
}
45
45
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
+
46
54
pure fn chain < T , U > ( opt : option < T > , f : fn ( T ) -> option < U > ) -> option < U > {
47
55
/*!
48
56
* Update an optional value by optionally running its content through a
@@ -128,7 +136,7 @@ impl extensions<T> for option<T> {
128
136
/// Returns true if the option contains some value
129
137
pure fn is_some ( ) -> bool { is_some ( self ) }
130
138
/// 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) }
132
140
}
133
141
134
142
impl extensions < T : copy > for option < T > {
0 commit comments