diff options
Diffstat (limited to 'src/libcore/either.rs')
| -rw-r--r-- | src/libcore/either.rs | 46 |
1 files changed, 23 insertions, 23 deletions
diff --git a/src/libcore/either.rs b/src/libcore/either.rs index 00a39416748..564966c1493 100644 --- a/src/libcore/either.rs +++ b/src/libcore/either.rs @@ -21,28 +21,28 @@ fn either<T, U, V>(f_left: fn(T) -> V, alt value { left(l) { f_left(l) } right(r) { f_right(r) } } } -fn lefts<T: copy, U>(eithers: [either<T, U>]) -> [T] { +fn lefts<T: copy, U>(eithers: [either<T, U>]/~) -> [T]/~ { #[doc = "Extracts from a vector of either all the left values"]; - let mut result: [T] = []; + let mut result: [T]/~ = []/~; for vec::each(eithers) {|elt| - alt elt { left(l) { result += [l]; } _ {/* fallthrough */ } } + alt elt { left(l) { result += [l]/~; } _ {/* fallthrough */ } } } ret result; } -fn rights<T, U: copy>(eithers: [either<T, U>]) -> [U] { +fn rights<T, U: copy>(eithers: [either<T, U>]/~) -> [U]/~ { #[doc = "Extracts from a vector of either all the right values"]; - let mut result: [U] = []; + let mut result: [U]/~ = []/~; for vec::each(eithers) {|elt| - alt elt { right(r) { result += [r]; } _ {/* fallthrough */ } } + alt elt { right(r) { result += [r]/~; } _ {/* fallthrough */ } } } ret result; } -fn partition<T: copy, U: copy>(eithers: [either<T, U>]) - -> {lefts: [T], rights: [U]} { +fn partition<T: copy, U: copy>(eithers: [either<T, U>]/~) + -> {lefts: [T]/~, rights: [U]/~} { #[doc = " Extracts from a vector of either all the left values and right values @@ -50,10 +50,10 @@ fn partition<T: copy, U: copy>(eithers: [either<T, U>]) right values. "]; - let mut lefts: [T] = []; - let mut rights: [U] = []; + let mut lefts: [T]/~ = []/~; + let mut rights: [U]/~ = []/~; for vec::each(eithers) {|elt| - alt elt { left(l) { lefts += [l]; } right(r) { rights += [r]; } } + alt elt { left(l) { lefts += [l]/~; } right(r) { rights += [r]/~; } } } ret {lefts: lefts, rights: rights}; } @@ -112,49 +112,49 @@ fn test_either_right() { #[test] fn test_lefts() { - let input = [left(10), right(11), left(12), right(13), left(14)]; + let input = [left(10), right(11), left(12), right(13), left(14)]/~; let result = lefts(input); - assert (result == [10, 12, 14]); + assert (result == [10, 12, 14]/~); } #[test] fn test_lefts_none() { - let input: [either<int, int>] = [right(10), right(10)]; + let input: [either<int, int>]/~ = [right(10), right(10)]/~; let result = lefts(input); assert (vec::len(result) == 0u); } #[test] fn test_lefts_empty() { - let input: [either<int, int>] = []; + let input: [either<int, int>]/~ = []/~; let result = lefts(input); assert (vec::len(result) == 0u); } #[test] fn test_rights() { - let input = [left(10), right(11), left(12), right(13), left(14)]; + let input = [left(10), right(11), left(12), right(13), left(14)]/~; let result = rights(input); - assert (result == [11, 13]); + assert (result == [11, 13]/~); } #[test] fn test_rights_none() { - let input: [either<int, int>] = [left(10), left(10)]; + let input: [either<int, int>]/~ = [left(10), left(10)]/~; let result = rights(input); assert (vec::len(result) == 0u); } #[test] fn test_rights_empty() { - let input: [either<int, int>] = []; + let input: [either<int, int>]/~ = []/~; let result = rights(input); assert (vec::len(result) == 0u); } #[test] fn test_partition() { - let input = [left(10), right(11), left(12), right(13), left(14)]; + let input = [left(10), right(11), left(12), right(13), left(14)]/~; let result = partition(input); assert (result.lefts[0] == 10); assert (result.lefts[1] == 12); @@ -165,7 +165,7 @@ fn test_partition() { #[test] fn test_partition_no_lefts() { - let input: [either<int, int>] = [right(10), right(11)]; + let input: [either<int, int>]/~ = [right(10), right(11)]/~; let result = partition(input); assert (vec::len(result.lefts) == 0u); assert (vec::len(result.rights) == 2u); @@ -173,7 +173,7 @@ fn test_partition_no_lefts() { #[test] fn test_partition_no_rights() { - let input: [either<int, int>] = [left(10), left(11)]; + let input: [either<int, int>]/~ = [left(10), left(11)]/~; let result = partition(input); assert (vec::len(result.lefts) == 2u); assert (vec::len(result.rights) == 0u); @@ -181,7 +181,7 @@ fn test_partition_no_rights() { #[test] fn test_partition_empty() { - let input: [either<int, int>] = []; + let input: [either<int, int>]/~ = []/~; let result = partition(input); assert (vec::len(result.lefts) == 0u); assert (vec::len(result.rights) == 0u); |
