about summary refs log tree commit diff
path: root/src/libstd/option.rs
diff options
context:
space:
mode:
authorErick Tryzelaar <erick.tryzelaar@gmail.com>2013-09-11 12:52:17 -0700
committerErick Tryzelaar <erick.tryzelaar@gmail.com>2013-09-12 18:54:13 -0700
commit38f97ea10313ba9a8c6f57fbf73ff8daf5376e8b (patch)
tree72966f38845b07f6f43291d06957634135d97030 /src/libstd/option.rs
parente03d60e9ebf2dbc2d18ab9919f905c17b967fcde (diff)
std: Rename {Option,Result}::chain{,_err}* to {and_then,or_else}
Diffstat (limited to 'src/libstd/option.rs')
-rw-r--r--src/libstd/option.rs42
1 files changed, 6 insertions, 36 deletions
diff --git a/src/libstd/option.rs b/src/libstd/option.rs
index cd9e3980716..9b5b28d5ceb 100644
--- a/src/libstd/option.rs
+++ b/src/libstd/option.rs
@@ -141,9 +141,9 @@ impl<T> Option<T> {
     /// Returns `None` if the option is `None`, otherwise calls and returns the
     /// value of `f`.
     #[inline]
-    pub fn and_then(self, f: &fn() -> Option<T>) -> Option<T> {
+    pub fn and_then<U>(self, f: &fn(T) -> Option<U>) -> Option<U> {
         match self {
-            Some(_) => f(),
+            Some(x) => f(x),
             None => None,
         }
     }
@@ -167,36 +167,6 @@ impl<T> Option<T> {
         }
     }
 
-    /// Update an optional value by optionally running its content through a
-    /// function that returns an option.
-    #[inline]
-    pub fn chain<U>(self, f: &fn(T) -> Option<U>) -> Option<U> {
-        match self {
-            Some(t) => f(t),
-            None => None
-        }
-    }
-
-    /// Update an optional value by optionally running its content by reference
-    /// through a function that returns an option.
-    #[inline]
-    pub fn chain_ref<'a, U>(&'a self, f: &fn(x: &'a T) -> Option<U>) -> Option<U> {
-        match *self {
-            Some(ref x) => f(x),
-            None => None
-        }
-    }
-
-    /// Update an optional value by optionally running its content by mut reference
-    /// through a function that returns an option.
-    #[inline]
-    pub fn chain_mut_ref<'a, U>(&'a mut self, f: &fn(x: &'a mut T) -> Option<U>) -> Option<U> {
-        match *self {
-            Some(ref mut x) => f(x),
-            None => None
-        }
-    }
-
     /// Filters an optional value using given function.
     #[inline(always)]
     pub fn filtered(self, f: &fn(t: &T) -> bool) -> Option<T> {
@@ -637,12 +607,12 @@ mod tests {
     #[test]
     fn test_and_then() {
         let x: Option<int> = Some(1);
-        assert_eq!(x.and_then(|| Some(2)), Some(2));
-        assert_eq!(x.and_then(|| None), None);
+        assert_eq!(x.and_then(|x| Some(x + 1)), Some(2));
+        assert_eq!(x.and_then(|_| None::<int>), None);
 
         let x: Option<int> = None;
-        assert_eq!(x.and_then(|| Some(2)), None);
-        assert_eq!(x.and_then(|| None), None);
+        assert_eq!(x.and_then(|x| Some(x + 1)), None);
+        assert_eq!(x.and_then(|_| None::<int>), None);
     }
 
     #[test]