diff options
| author | Brian Anderson <andersrb@gmail.com> | 2011-05-22 01:25:03 -0400 |
|---|---|---|
| committer | Brian Anderson <andersrb@gmail.com> | 2011-05-22 12:28:27 -0400 |
| commit | 443e1e455756df60c93a71b13dc132e289b7f032 (patch) | |
| tree | 19b439b828a3a6f72e961d7ecc6b8149b24d623e | |
| parent | 820ccf4a1335dd3940118e41f72a11bd654bac99 (diff) | |
| download | rust-443e1e455756df60c93a71b13dc132e289b7f032.tar.gz rust-443e1e455756df60c93a71b13dc132e289b7f032.zip | |
stdlib: Use if/alt expressions in std::option
| -rw-r--r-- | src/lib/option.rs | 34 |
1 files changed, 16 insertions, 18 deletions
diff --git a/src/lib/option.rs b/src/lib/option.rs index 371fedf24d5..fe42132721a 100644 --- a/src/lib/option.rs +++ b/src/lib/option.rs @@ -8,34 +8,32 @@ tag t[T] { type operator[T, U] = fn(&T) -> U; fn get[T](&t[T] opt) -> T { - alt (opt) { + ret alt (opt) { case (some[T](?x)) { - ret x; + x } case (none[T]) { - fail; + fail } - } - fail; // FIXME: remove me when exhaustiveness checking works + }; } fn map[T, U](&operator[T, U] f, &t[T] opt) -> t[U] { - alt (opt) { + ret alt (opt) { case (some[T](?x)) { - ret some[U](f(x)); + some[U](f(x)) } case (none[T]) { - ret none[U]; + none[U] } - } - fail; // FIXME: remove me when exhaustiveness checking works + }; } fn is_none[T](&t[T] opt) -> bool { - alt (opt) { - case (none[T]) { ret true; } - case (some[T](_)) { ret false; } - } + ret alt (opt) { + case (none[T]) { true } + case (some[T](_)) { false } + }; } fn from_maybe[T](&T def, &t[T] opt) -> T { @@ -44,10 +42,10 @@ fn from_maybe[T](&T def, &t[T] opt) -> T { } fn maybe[T, U](&U def, fn(&T) -> U f, &t[T] opt) -> U { - alt (opt) { - case (none[T]) { ret def; } - case (some[T](?t)) { ret f(t); } - } + ret alt (opt) { + case (none[T]) { def } + case (some[T](?t)) { f(t) } + }; } // Can be defined in terms of the above when/if we have const bind. |
