add Option map_consume_default method

This commit is contained in:
Daniel Micay 2013-01-13 00:56:50 -05:00
parent a33966b2f2
commit 65a0125f7f

View File

@ -277,6 +277,13 @@ impl<T> Option<T> {
map_default(self, move def, f)
}
/// As `map_default`, but consumes the option and gives `f`
/// ownership to avoid copying.
#[inline(always)]
pure fn map_consume_default<U>(self, def: U, f: fn(v: T) -> U) -> U {
match self { None => def, Some(v) => f(v) }
}
/// Performs an operation on the contained value by reference
#[inline(always)]
pure fn iter(&self, f: fn(x: &T)) { iter(self, f) }