auto merge of #4874 : thestinger/rust/option, r=catamorphism
This commit is contained in:
commit
210fa2d017
|
@ -201,7 +201,7 @@ pub pure fn map_default<T, U>(opt: &r/Option<T>, def: U,
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub pure fn iter<T>(opt: &Option<T>, f: fn(x: &T)) {
|
||||
pub pure fn iter<T>(opt: &r/Option<T>, f: fn(x: &r/T)) {
|
||||
//! Performs an operation on the contained value by reference
|
||||
match *opt { None => (), Some(ref t) => f(t) }
|
||||
}
|
||||
|
@ -313,7 +313,7 @@ impl<T> Option<T> {
|
|||
|
||||
/// Performs an operation on the contained value by reference
|
||||
#[inline(always)]
|
||||
pure fn iter(&self, f: fn(x: &T)) { iter(self, f) }
|
||||
pure fn iter(&self, f: fn(x: &self/T)) { iter(self, f) }
|
||||
|
||||
/**
|
||||
Gets an immutable reference to the value inside an option.
|
||||
|
|
|
@ -561,18 +561,18 @@ impl <K: Ord, V> TreeNode<K, V> {
|
|||
|
||||
pure fn each<K: Ord, V>(node: &r/Option<~TreeNode<K, V>>,
|
||||
f: fn(&(&r/K, &r/V)) -> bool) {
|
||||
do node.map |x| {
|
||||
do node.iter |x| {
|
||||
each(&x.left, f);
|
||||
if f(&(&x.key, &x.value)) { each(&x.right, f) }
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
pure fn each_reverse<K: Ord, V>(node: &r/Option<~TreeNode<K, V>>,
|
||||
f: fn(&(&r/K, &r/V)) -> bool) {
|
||||
do node.map |x| {
|
||||
do node.iter |x| {
|
||||
each_reverse(&x.right, f);
|
||||
if f(&(&x.key, &x.value)) { each_reverse(&x.left, f) }
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// Remove left horizontal link by rotating right
|
||||
|
|
Loading…
Reference in New Issue