Skip to content

Commit 449fc76

Browse files
committed
---
yaml --- r: 36818 b: refs/heads/try2 c: 938058b h: refs/heads/master v: v3
1 parent 77f2792 commit 449fc76

File tree

3 files changed

+140
-15
lines changed

3 files changed

+140
-15
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: eb8fd119c65c67f3b1b8268cc7341c22d39b7b61
55
refs/heads/try: d324a424d8f84b1eb049b12cf34182bda91b0024
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 97ddf3c7bdbd874ad6596e9444abb61b5903bc04
8+
refs/heads/try2: 938058b0040e3c482e10b78eeef7afb941b2b64e
99
refs/heads/incoming: d9317a174e434d4c99fc1a37fd7dc0d2f5328d37
1010
refs/heads/dist-snap: 22efa39382d41b084fde1719df7ae8ce5697d8c9
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596

branches/try2/src/libcore/vec.rs

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2024,6 +2024,32 @@ impl<A> &[A]: iter::BaseIter<A> {
20242024
pure fn size_hint(&self) -> Option<uint> { Some(len(*self)) }
20252025
}
20262026

2027+
// FIXME(#4148): This should be redundant
2028+
impl<A> ~[A]: iter::BaseIter<A> {
2029+
pub pure fn each(&self, blk: fn(v: &A) -> bool) {
2030+
// FIXME(#2263)---should be able to call each(self, blk)
2031+
for each(*self) |e| {
2032+
if (!blk(e)) {
2033+
return;
2034+
}
2035+
}
2036+
}
2037+
pure fn size_hint(&self) -> Option<uint> { Some(len(*self)) }
2038+
}
2039+
2040+
// FIXME(#4148): This should be redundant
2041+
impl<A> @[A]: iter::BaseIter<A> {
2042+
pub pure fn each(&self, blk: fn(v: &A) -> bool) {
2043+
// FIXME(#2263)---should be able to call each(self, blk)
2044+
for each(*self) |e| {
2045+
if (!blk(e)) {
2046+
return;
2047+
}
2048+
}
2049+
}
2050+
pure fn size_hint(&self) -> Option<uint> { Some(len(*self)) }
2051+
}
2052+
20272053
impl<A> &[A]: iter::ExtendedIter<A> {
20282054
pub pure fn eachi(&self, blk: fn(uint, v: &A) -> bool) {
20292055
iter::eachi(self, blk)
@@ -2049,11 +2075,75 @@ impl<A> &[A]: iter::ExtendedIter<A> {
20492075
}
20502076
}
20512077

2078+
// FIXME(#4148): This should be redundant
2079+
impl<A> ~[A]: iter::ExtendedIter<A> {
2080+
pub pure fn eachi(&self, blk: fn(uint, v: &A) -> bool) {
2081+
iter::eachi(self, blk)
2082+
}
2083+
pub pure fn all(&self, blk: fn(&A) -> bool) -> bool {
2084+
iter::all(self, blk)
2085+
}
2086+
pub pure fn any(&self, blk: fn(&A) -> bool) -> bool {
2087+
iter::any(self, blk)
2088+
}
2089+
pub pure fn foldl<B>(&self, b0: B, blk: fn(&B, &A) -> B) -> B {
2090+
iter::foldl(self, b0, blk)
2091+
}
2092+
pub pure fn position(&self, f: fn(&A) -> bool) -> Option<uint> {
2093+
iter::position(self, f)
2094+
}
2095+
pure fn map_to_vec<B>(&self, op: fn(&A) -> B) -> ~[B] {
2096+
iter::map_to_vec(self, op)
2097+
}
2098+
pure fn flat_map_to_vec<B,IB:BaseIter<B>>(&self, op: fn(&A) -> IB)
2099+
-> ~[B] {
2100+
iter::flat_map_to_vec(self, op)
2101+
}
2102+
}
2103+
2104+
// FIXME(#4148): This should be redundant
2105+
impl<A> @[A]: iter::ExtendedIter<A> {
2106+
pub pure fn eachi(&self, blk: fn(uint, v: &A) -> bool) {
2107+
iter::eachi(self, blk)
2108+
}
2109+
pub pure fn all(&self, blk: fn(&A) -> bool) -> bool {
2110+
iter::all(self, blk)
2111+
}
2112+
pub pure fn any(&self, blk: fn(&A) -> bool) -> bool {
2113+
iter::any(self, blk)
2114+
}
2115+
pub pure fn foldl<B>(&self, b0: B, blk: fn(&B, &A) -> B) -> B {
2116+
iter::foldl(self, b0, blk)
2117+
}
2118+
pub pure fn position(&self, f: fn(&A) -> bool) -> Option<uint> {
2119+
iter::position(self, f)
2120+
}
2121+
pure fn map_to_vec<B>(&self, op: fn(&A) -> B) -> ~[B] {
2122+
iter::map_to_vec(self, op)
2123+
}
2124+
pure fn flat_map_to_vec<B,IB:BaseIter<B>>(&self, op: fn(&A) -> IB)
2125+
-> ~[B] {
2126+
iter::flat_map_to_vec(self, op)
2127+
}
2128+
}
2129+
20522130
impl<A: Eq> &[A]: iter::EqIter<A> {
20532131
pub pure fn contains(&self, x: &A) -> bool { iter::contains(self, x) }
20542132
pub pure fn count(&self, x: &A) -> uint { iter::count(self, x) }
20552133
}
20562134

2135+
// FIXME(#4148): This should be redundant
2136+
impl<A: Eq> ~[A]: iter::EqIter<A> {
2137+
pub pure fn contains(&self, x: &A) -> bool { iter::contains(self, x) }
2138+
pub pure fn count(&self, x: &A) -> uint { iter::count(self, x) }
2139+
}
2140+
2141+
// FIXME(#4148): This should be redundant
2142+
impl<A: Eq> @[A]: iter::EqIter<A> {
2143+
pub pure fn contains(&self, x: &A) -> bool { iter::contains(self, x) }
2144+
pub pure fn count(&self, x: &A) -> uint { iter::count(self, x) }
2145+
}
2146+
20572147
impl<A: Copy> &[A]: iter::CopyableIter<A> {
20582148
pure fn filter_to_vec(&self, pred: fn(&A) -> bool) -> ~[A] {
20592149
iter::filter_to_vec(self, pred)
@@ -2064,11 +2154,45 @@ impl<A: Copy> &[A]: iter::CopyableIter<A> {
20642154
}
20652155
}
20662156

2157+
// FIXME(#4148): This should be redundant
2158+
impl<A: Copy> ~[A]: iter::CopyableIter<A> {
2159+
pure fn filter_to_vec(&self, pred: fn(&A) -> bool) -> ~[A] {
2160+
iter::filter_to_vec(self, pred)
2161+
}
2162+
pure fn to_vec(&self) -> ~[A] { iter::to_vec(self) }
2163+
pub pure fn find(&self, f: fn(&A) -> bool) -> Option<A> {
2164+
iter::find(self, f)
2165+
}
2166+
}
2167+
2168+
// FIXME(#4148): This should be redundant
2169+
impl<A: Copy> @[A]: iter::CopyableIter<A> {
2170+
pure fn filter_to_vec(&self, pred: fn(&A) -> bool) -> ~[A] {
2171+
iter::filter_to_vec(self, pred)
2172+
}
2173+
pure fn to_vec(&self) -> ~[A] { iter::to_vec(self) }
2174+
pub pure fn find(&self, f: fn(&A) -> bool) -> Option<A> {
2175+
iter::find(self, f)
2176+
}
2177+
}
2178+
20672179
impl<A: Copy Ord> &[A]: iter::CopyableOrderedIter<A> {
20682180
pure fn min(&self) -> A { iter::min(self) }
20692181
pure fn max(&self) -> A { iter::max(self) }
20702182
}
20712183

2184+
// FIXME(#4148): This should be redundant
2185+
impl<A: Copy Ord> ~[A]: iter::CopyableOrderedIter<A> {
2186+
pure fn min(&self) -> A { iter::min(self) }
2187+
pure fn max(&self) -> A { iter::max(self) }
2188+
}
2189+
2190+
// FIXME(#4148): This should be redundant
2191+
impl<A: Copy Ord> @[A]: iter::CopyableOrderedIter<A> {
2192+
pure fn min(&self) -> A { iter::min(self) }
2193+
pure fn max(&self) -> A { iter::max(self) }
2194+
}
2195+
20722196
impl<A:Copy> &[A] : iter::CopyableNonstrictIter<A> {
20732197
pure fn each_val(&const self, f: fn(A) -> bool) {
20742198
let mut i = 0;
@@ -2079,6 +2203,7 @@ impl<A:Copy> &[A] : iter::CopyableNonstrictIter<A> {
20792203
}
20802204
}
20812205

2206+
// FIXME(#4148): This should be redundant
20822207
impl<A:Copy> ~[A] : iter::CopyableNonstrictIter<A> {
20832208
pure fn each_val(&const self, f: fn(A) -> bool) {
20842209
let mut i = 0;
@@ -2089,6 +2214,7 @@ impl<A:Copy> ~[A] : iter::CopyableNonstrictIter<A> {
20892214
}
20902215
}
20912216

2217+
// FIXME(#4148): This should be redundant
20922218
impl<A:Copy> @[A] : iter::CopyableNonstrictIter<A> {
20932219
pure fn each_val(&const self, f: fn(A) -> bool) {
20942220
let mut i = 0;

branches/try2/src/test/run-pass/iter-flat-map-to-vec.rs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,22 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// xfail-test -- flat_map_to_vec currently disable
12-
fn repeat(x: &uint) -> ~[uint] { ~[x, x] }
11+
fn repeat(x: &uint) -> ~[uint] { ~[*x, *x] }
1312

14-
fn incd_if_even(x: &uint) -> option<uint> {
15-
if (x % 2u) == 0u {some(x + 1u)} else {none}
13+
fn incd_if_even(x: &uint) -> Option<uint> {
14+
if (*x % 2u) == 0u {Some(*x + 1u)} else {None}
1615
}
1716

1817
fn main() {
19-
assert ~[1u, 3u].flat_map_to_vec(repeat) == ~[1u, 1u, 3u, 3u];
20-
assert ~[].flat_map_to_vec(repeat) == ~[];
21-
assert none.flat_map_to_vec(repeat) == ~[];
22-
assert some(1u).flat_map_to_vec(repeat) == ~[1u, 1u];
23-
assert some(2u).flat_map_to_vec(repeat) == ~[2u, 2u];
18+
assert (~[1u, 3u]).flat_map_to_vec(repeat) == ~[1u, 1u, 3u, 3u];
19+
assert (~[]).flat_map_to_vec(repeat) == ~[];
20+
assert None.flat_map_to_vec(repeat) == ~[];
21+
assert Some(1u).flat_map_to_vec(repeat) == ~[1u, 1u];
22+
assert Some(2u).flat_map_to_vec(repeat) == ~[2u, 2u];
2423

25-
assert ~[1u, 2u, 5u].flat_map_to_vec(incd_if_even) == ~[3u];
26-
assert ~[].flat_map_to_vec(incd_if_even) == ~[];
27-
assert none.flat_map_to_vec(incd_if_even) == ~[];
28-
assert some(1u).flat_map_to_vec(incd_if_even) == ~[];
29-
assert some(2u).flat_map_to_vec(incd_if_even) == ~[3u];
24+
assert (~[1u, 2u, 5u]).flat_map_to_vec(incd_if_even) == ~[3u];
25+
assert (~[]).flat_map_to_vec(incd_if_even) == ~[];
26+
assert None.flat_map_to_vec(incd_if_even) == ~[];
27+
assert Some(1u).flat_map_to_vec(incd_if_even) == ~[];
28+
assert Some(2u).flat_map_to_vec(incd_if_even) == ~[3u];
3029
}

0 commit comments

Comments
 (0)