diff --git a/src/libcore/option.rs b/src/libcore/option.rs index e5d703eec4ae..cfc2cba92260 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -102,7 +102,7 @@ pub pure fn get_ref(opt: &r/Option) -> &r/T { } #[inline(always)] -pub pure fn map(opt: &Option, f: fn(x: &T) -> U) -> Option { +pub pure fn map(opt: &r/Option, f: fn(x: &r/T) -> U) -> Option { //! Maps a `some` value by reference from one type to another match *opt { Some(ref x) => Some(f(x)), None => None } @@ -193,8 +193,8 @@ pub pure fn get_or_default(opt: Option, def: T) -> T { } #[inline(always)] -pub pure fn map_default(opt: &Option, def: U, - f: fn(x: &T) -> U) -> U { +pub pure fn map_default(opt: &r/Option, def: U, + f: fn(&r/T) -> U) -> U { //! Applies a function to the contained value or returns a default match *opt { None => move def, Some(ref t) => f(t) } @@ -273,7 +273,7 @@ impl Option { /// Maps a `some` value from one type to another by reference #[inline(always)] - pure fn map(&self, f: fn(x: &T) -> U) -> Option { map(self, f) } + pure fn map(&self, f: fn(&self/T) -> U) -> Option { map(self, f) } /// As `map`, but consumes the option and gives `f` ownership to avoid /// copying. @@ -284,7 +284,7 @@ impl Option { /// Applies a function to the contained value or returns a default #[inline(always)] - pure fn map_default(&self, def: U, f: fn(x: &T) -> U) -> U { + pure fn map_default(&self, def: U, f: fn(&self/T) -> U) -> U { map_default(self, move def, f) } diff --git a/src/libstd/treemap.rs b/src/libstd/treemap.rs index e79025a79555..da83c7b789b0 100644 --- a/src/libstd/treemap.rs +++ b/src/libstd/treemap.rs @@ -556,24 +556,18 @@ impl TreeNode { pure fn each(node: &r/Option<~TreeNode>, f: fn(&(&r/K, &r/V)) -> bool) { - match *node { - Some(ref x) => { + do node.map |x| { each(&x.left, f); if f(&(&x.key, &x.value)) { each(&x.right, f) } - } - None => () - } + }; } pure fn each_reverse(node: &r/Option<~TreeNode>, f: fn(&(&r/K, &r/V)) -> bool) { - match *node { - Some(ref x) => { + do node.map |x| { each_reverse(&x.right, f); if f(&(&x.key, &x.value)) { each_reverse(&x.left, f) } - } - None => () - } + }; } // Remove left horizontal link by rotating right