Skip to content

Commit 608b6c5

Browse files
author
Jorge Aparicio
committed
---
yaml --- r: 163264 b: refs/heads/snap-stage3 c: 216bcfd h: refs/heads/master v: v3
1 parent f16fce8 commit 608b6c5

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 9146a919b616e39e528e4d7100d16eef52f1f852
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: a50c587242903f5c3d69e3684c8a79d3dcd849b7
4+
refs/heads/snap-stage3: 216bcfd66b63a9f60e41e4b736145f62edda4150
55
refs/heads/try: 20cbbffeefc1f35e2ea63afce7b42fbd79611d42
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d

branches/snap-stage3/src/libcore/iter.rs

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2108,19 +2108,18 @@ impl<A, I, F> RandomAccessIterator<A> for Inspect<A, I, F> where
21082108
/// }
21092109
/// ```
21102110
#[experimental]
2111-
pub struct Unfold<'a, A, St> {
2112-
f: |&mut St|: 'a -> Option<A>,
2111+
pub struct Unfold<A, St, F> where F: FnMut(&mut St) -> Option<A> {
2112+
f: F,
21132113
/// Internal state that will be passed to the closure on the next iteration
21142114
pub state: St,
21152115
}
21162116

21172117
#[experimental]
2118-
impl<'a, A, St> Unfold<'a, A, St> {
2118+
impl<A, St, F> Unfold<A, St, F> where F: FnMut(&mut St) -> Option<A> {
21192119
/// Creates a new iterator with the specified closure as the "iterator
21202120
/// function" and an initial state to eventually pass to the closure
21212121
#[inline]
2122-
pub fn new<'a>(initial_state: St, f: |&mut St|: 'a -> Option<A>)
2123-
-> Unfold<'a, A, St> {
2122+
pub fn new(initial_state: St, f: F) -> Unfold<A, St, F> {
21242123
Unfold {
21252124
f: f,
21262125
state: initial_state
@@ -2129,7 +2128,7 @@ impl<'a, A, St> Unfold<'a, A, St> {
21292128
}
21302129

21312130
#[experimental]
2132-
impl<'a, A, St> Iterator<A> for Unfold<'a, A, St> {
2131+
impl<A, St, F> Iterator<A> for Unfold<A, St, F> where F: FnMut(&mut St) -> Option<A> {
21332132
#[inline]
21342133
fn next(&mut self) -> Option<A> {
21352134
(self.f)(&mut self.state)
@@ -2456,18 +2455,24 @@ impl<A: Clone> RandomAccessIterator<A> for Repeat<A> {
24562455
fn idx(&mut self, _: uint) -> Option<A> { Some(self.element.clone()) }
24572456
}
24582457

2459-
type IterateState<'a, T> = (|T|: 'a -> T, Option<T>, bool);
2458+
type IterateState<T, F> = (F, Option<T>, bool);
24602459

24612460
/// An iterator that repeatedly applies a given function, starting
24622461
/// from a given seed value.
24632462
#[experimental]
2464-
pub type Iterate<'a, T> = Unfold<'a, T, IterateState<'a, T>>;
2463+
pub type Iterate<T, F> = Unfold<T, IterateState<T, F>, fn(&mut IterateState<T, F>) -> Option<T>>;
24652464

24662465
/// Create a new iterator that produces an infinite sequence of
24672466
/// repeated applications of the given function `f`.
24682467
#[experimental]
2469-
pub fn iterate<'a, T: Clone>(seed: T, f: |T|: 'a -> T) -> Iterate<'a, T> {
2470-
Unfold::new((f, Some(seed), true), |st| {
2468+
pub fn iterate<T, F>(seed: T, f: F) -> Iterate<T, F> where
2469+
T: Clone,
2470+
F: FnMut(T) -> T,
2471+
{
2472+
fn next<T, F>(st: &mut IterateState<T, F>) -> Option<T> where
2473+
T: Clone,
2474+
F: FnMut(T) -> T,
2475+
{
24712476
let &(ref mut f, ref mut val, ref mut first) = st;
24722477
if *first {
24732478
*first = false;
@@ -2480,7 +2485,9 @@ pub fn iterate<'a, T: Clone>(seed: T, f: |T|: 'a -> T) -> Iterate<'a, T> {
24802485
}
24812486
}
24822487
val.clone()
2483-
})
2488+
}
2489+
2490+
Unfold::new((f, Some(seed), true), next)
24842491
}
24852492

24862493
/// Create a new iterator that endlessly repeats the element `elt`.

0 commit comments

Comments
 (0)