|
14 | 14 |
|
15 | 15 | // returns an infinite iterator of repeated applications of f to x,
|
16 | 16 | // i.e. [x, f(x), f(f(x)), ...], as haskell iterate function.
|
17 |
| -fn iterate<'a, T>(f: &'a fn(&T) -> T, x: T) -> Iterate<'a, T> { |
18 |
| - Iterate::new(f, x) |
| 17 | +fn iterate<'a, T>(x: T, f: &'a fn(&T) -> T) -> Iterate<'a, T> { |
| 18 | + Iterate {f: f, next: x} |
19 | 19 | }
|
20 | 20 | struct Iterate<'self, T> {
|
21 | 21 | priv f: &'self fn(&T) -> T,
|
22 | 22 | priv next: T
|
23 | 23 | }
|
24 |
| -impl<'self, T> Iterate<'self, T> { |
25 |
| - fn new<'a>(f: &'a fn(&T) -> T, x: T) -> Iterate<'a, T> { |
26 |
| - Iterate {f: f, next: x} |
27 |
| - } |
28 |
| -} |
29 | 24 | impl<'self, T> Iterator<T> for Iterate<'self, T> {
|
30 | 25 | fn next(&mut self) -> Option<T> {
|
31 | 26 | let mut res = (self.f)(&self.next);
|
@@ -71,11 +66,11 @@ impl<'self, T> Iterator<&'self T> for ListIterator<'self, T> {
|
71 | 66 | fn transform(p: ~[(int, int)], all: bool) -> ~[~[(int, int)]] {
|
72 | 67 | let mut res =
|
73 | 68 | // rotations
|
74 |
| - iterate(|p| p.iter().map(|&(y, x)| (x + y, -y)).collect(), p) |
| 69 | + iterate(p, |p| p.iter().map(|&(y, x)| (x + y, -y)).collect()) |
75 | 70 | .take(if all {6} else {3})
|
76 | 71 | // mirror
|
77 | 72 | .flat_map(|p| {
|
78 |
| - iterate(|p| p.iter().map(|&(y, x)| (x, y)).collect(), p).take(2) |
| 73 | + iterate(p, |p| p.iter().map(|&(y, x)| (x, y)).collect()).take(2) |
79 | 74 | }).to_owned_vec();
|
80 | 75 |
|
81 | 76 | // translating to (0, 0) as minimum coordinates.
|
|
0 commit comments