@@ -119,11 +119,9 @@ pub pure fn chain<T, U>(opt: Option<T>,
|
|||||||
* function that returns an option.
|
* function that returns an option.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// XXX write with move match
|
match move opt {
|
||||||
if opt.is_some() {
|
Some(move t) => f(t),
|
||||||
f(unwrap(opt))
|
None => None
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -105,11 +105,9 @@ pub pure fn to_either<T: Copy, U: Copy>(res: &Result<U, T>)
|
|||||||
*/
|
*/
|
||||||
pub fn chain<T, U: Copy, V: Copy>(res: Result<T, V>, op: fn(t: T)
|
pub fn chain<T, U: Copy, V: Copy>(res: Result<T, V>, op: fn(t: T)
|
||||||
-> Result<U, V>) -> Result<U, V> {
|
-> Result<U, V>) -> Result<U, V> {
|
||||||
// XXX: Should be writable with move + match
|
match move res {
|
||||||
if res.is_ok() {
|
Ok(move t) => op(t),
|
||||||
op(unwrap(res))
|
Err(move e) => Err(e)
|
||||||
} else {
|
|
||||||
Err(unwrap_err(res))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user