diff options
| author | Tim Chevalier <chevalier@alum.wellesley.edu> | 2012-04-02 15:34:49 -0700 |
|---|---|---|
| committer | Tim Chevalier <chevalier@alum.wellesley.edu> | 2012-04-02 16:12:49 -0700 |
| commit | 21be1379d561b6679a8a2ea47dce88f948c5acca (patch) | |
| tree | 25b911b9e5071d1512a3e5ff5d66b91716645c75 /src/libcore | |
| parent | 987bc2362926d0672a01e8d5964940743df48cb6 (diff) | |
| download | rust-21be1379d561b6679a8a2ea47dce88f948c5acca.tar.gz rust-21be1379d561b6679a8a2ea47dce88f948c5acca.zip | |
Rename some core::option functions
from_maybe => get_with_default maybe => with_option may => with_option_do I know these names are kind of ridiculous, but it's the best I could think of. Feel free to bikeshed. Closes #2081
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/iter.rs | 2 | ||||
| -rw-r--r-- | src/libcore/option.rs | 13 | ||||
| -rw-r--r-- | src/libcore/os.rs | 7 | ||||
| -rw-r--r-- | src/libcore/result.rs | 7 | ||||
| -rw-r--r-- | src/libcore/task.rs | 2 |
5 files changed, 16 insertions, 15 deletions
diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs index e5cb78c38d4..9e8abefb4a0 100644 --- a/src/libcore/iter.rs +++ b/src/libcore/iter.rs @@ -29,7 +29,7 @@ impl<A> of iterable<A> for [A] { impl<A> of iterable<A> for option<A> { fn iter(blk: fn(A)) { - option::may(self, blk) + option::with_option_do(self, blk) } } diff --git a/src/libcore/option.rs b/src/libcore/option.rs index d89593f14c4..daf9a229354 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -52,19 +52,19 @@ pure fn is_some<T>(opt: option<T>) -> bool { !is_none(opt) } -pure fn from_maybe<T: copy>(opt: option<T>, def: T) -> T { +pure fn get_or_default<T: copy>(opt: option<T>, def: T) -> T { #[doc = "Returns the contained value or a default"]; alt opt { some(x) { x } none { def } } } -fn maybe<T, U: copy>(opt: option<T>, def: U, f: fn(T) -> U) -> U { +fn with_option<T, U: copy>(opt: option<T>, def: U, f: fn(T) -> U) -> U { #[doc = "Applies a function to the contained value or returns a default"]; alt opt { none { def } some(t) { f(t) } } } -fn may<T>(opt: option<T>, f: fn(T)) { +fn with_option_do<T>(opt: option<T>, f: fn(T)) { #[doc = "Performs an operation on the contained value or does nothing"]; alt opt { none { } some(t) { f(t); } } @@ -94,11 +94,12 @@ impl extensions<T:copy> for option<T> { "] fn chain<U>(f: fn(T) -> option<U>) -> option<U> { chain(self, f) } #[doc = "Returns the contained value or a default"] - fn from_maybe(def: T) -> T { from_maybe(self, def) } + fn get_or_default(def: T) -> T { get_or_default(self, def) } #[doc = "Applies a function to the contained value or returns a default"] - fn maybe<U: copy>(def: U, f: fn(T) -> U) -> U { maybe(self, def, f) } + fn with_option<U: copy>(def: U, f: fn(T) -> U) -> U + { with_option(self, def, f) } #[doc = "Performs an operation on the contained value or does nothing"] - fn may(f: fn(T)) { may(self, f) } + fn with_option_do(f: fn(T)) { with_option_do(self, f) } #[doc = " Gets the value out of an option diff --git a/src/libcore/os.rs b/src/libcore/os.rs index 16a5b0f36f2..3e7b2dba943 100644 --- a/src/libcore/os.rs +++ b/src/libcore/os.rs @@ -702,7 +702,7 @@ mod tests { setenv("HOME", ""); assert os::homedir() == none; - option::may(oldhome, {|s| setenv("HOME", s)}); + option::with_option_do(oldhome, {|s| setenv("HOME", s)}); } #[test] @@ -732,8 +732,9 @@ mod tests { setenv("USERPROFILE", "/home/PaloAlto"); assert os::homedir() == some("/home/MountainView"); - option::may(oldhome, {|s| setenv("HOME", s)}); - option::may(olduserprofile, {|s| setenv("USERPROFILE", s)}); + option::with_option_do(oldhome, {|s| setenv("HOME", s)}); + option::with_option_do(olduserprofile, + {|s| setenv("USERPROFILE", s)}); } // Issue #712 diff --git a/src/libcore/result.rs b/src/libcore/result.rs index a3f7cc3a4d8..3957bd31a10 100644 --- a/src/libcore/result.rs +++ b/src/libcore/result.rs @@ -20,10 +20,9 @@ If the result is an error pure fn get<T: copy, U>(res: result<T, U>) -> T { alt res { ok(t) { t } - err(_) { - // FIXME: Serialize the error value - // and include it in the fail message (maybe just note it) - fail "get called on error result"; + err(the_err) { + // FIXME: have a run-fail test for this + unchecked{ fail #fmt("get called on error result: %?", the_err); } } } } diff --git a/src/libcore/task.rs b/src/libcore/task.rs index dcd784fb2a3..dc2dd5d179e 100644 --- a/src/libcore/task.rs +++ b/src/libcore/task.rs @@ -498,7 +498,7 @@ fn spawn_raw(opts: task_opts, +f: fn~()) unsafe { } }; - option::may(opts.notify_chan) {|c| + option::with_option_do(opts.notify_chan) {|c| // FIXME (1087): Would like to do notification in Rust rustrt::rust_task_config_notify(new_task, c); } |
