Merge pull request #1317 from boggle/fix1315

fix to #1315 + small additions to std::either and result
This commit is contained in:
Graydon Hoare
2011-12-16 13:01:47 -08:00
14 changed files with 58 additions and 25 deletions

View File

@@ -181,7 +181,7 @@ Returns the first element of a vector
Predicates:
<is_not_empty> (v)
*/
fn head<copy T>(v: [const T]) : is_not_empty(v) -> T { ret v[0]; }
pure fn head<copy T>(v: [const T]) : is_not_empty(v) -> T { ret v[0]; }
/*
Function: tail
@@ -221,7 +221,7 @@ Returns:
An option containing the last element of `v` if `v` is not empty, or
none if `v` is empty.
*/
fn last<copy T>(v: [const T]) -> option::t<T> {
pure fn last<copy T>(v: [const T]) -> option::t<T> {
if len(v) == 0u { ret none; }
ret some(v[len(v) - 1u]);
}
@@ -234,7 +234,7 @@ Returns the last element of a non-empty vector `v`
Predicates:
<is_not_empty> (v)
*/
fn last_total<copy T>(v: [const T]) : is_not_empty(v) -> T {
pure fn last_total<copy T>(v: [const T]) : is_not_empty(v) -> T {
ret v[len(v) - 1u];
}