|
5 | 5 | use std::fmt;
|
6 | 6 | use std::mem;
|
7 | 7 |
|
8 |
| -/// See [`repeat_call`](crate::repeat_call) for more information. |
9 |
| -#[derive(Clone)] |
10 |
| -#[deprecated(note = "Use std repeat_with() instead", since = "0.8.0")] |
11 |
| -pub struct RepeatCall<F> { |
12 |
| - f: F, |
13 |
| -} |
14 |
| - |
15 |
| -impl<F> fmt::Debug for RepeatCall<F> { |
16 |
| - debug_fmt_fields!(RepeatCall,); |
17 |
| -} |
18 |
| - |
19 |
| -/// An iterator source that produces elements indefinitely by calling |
20 |
| -/// a given closure. |
21 |
| -/// |
22 |
| -/// Iterator element type is the return type of the closure. |
23 |
| -/// |
24 |
| -/// ``` |
25 |
| -/// use itertools::repeat_call; |
26 |
| -/// use itertools::Itertools; |
27 |
| -/// use std::collections::BinaryHeap; |
28 |
| -/// |
29 |
| -/// let mut heap = BinaryHeap::from(vec![2, 5, 3, 7, 8]); |
30 |
| -/// |
31 |
| -/// // extract each element in sorted order |
32 |
| -/// for element in repeat_call(|| heap.pop()).while_some() { |
33 |
| -/// print!("{}", element); |
34 |
| -/// } |
35 |
| -/// |
36 |
| -/// itertools::assert_equal( |
37 |
| -/// repeat_call(|| 1).take(5), |
38 |
| -/// vec![1, 1, 1, 1, 1] |
39 |
| -/// ); |
40 |
| -/// ``` |
41 |
| -#[deprecated(note = "Use std repeat_with() instead", since = "0.8.0")] |
42 |
| -pub fn repeat_call<F, A>(function: F) -> RepeatCall<F> |
43 |
| -where |
44 |
| - F: FnMut() -> A, |
45 |
| -{ |
46 |
| - RepeatCall { f: function } |
47 |
| -} |
48 |
| - |
49 |
| -impl<A, F> Iterator for RepeatCall<F> |
50 |
| -where |
51 |
| - F: FnMut() -> A, |
52 |
| -{ |
53 |
| - type Item = A; |
54 |
| - |
55 |
| - #[inline] |
56 |
| - fn next(&mut self) -> Option<Self::Item> { |
57 |
| - Some((self.f)()) |
58 |
| - } |
59 |
| - |
60 |
| - fn size_hint(&self) -> (usize, Option<usize>) { |
61 |
| - (usize::MAX, None) |
62 |
| - } |
63 |
| -} |
64 |
| - |
65 | 8 | /// Creates a new unfold source with the specified closure as the "iterator
|
66 | 9 | /// function" and an initial state to eventually pass to the closure
|
67 | 10 | ///
|
|
0 commit comments