Skip to content

Commit 8c9bc3c

Browse files
iterate: document a possible panic
1 parent 2f4739c commit 8c9bc3c

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/sources.rs

+12
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,18 @@ where
179179
///
180180
/// itertools::assert_equal(iterate(1, |&i| i * 3).take(5), vec![1, 3, 9, 27, 81]);
181181
/// ```
182+
///
183+
/// **Panics** if compute the next value does.
184+
///
185+
/// ```should_panic
186+
/// # use itertools::iterate;
187+
/// let mut it = iterate(25u32, |x| x - 10).take_while(|&x| x > 10);
188+
/// assert_eq!(it.next(), Some(25)); // `Iterate` holds 15.
189+
/// assert_eq!(it.next(), Some(15)); // `Iterate` holds 5.
190+
/// it.next(); // `5 - 10` overflows.
191+
/// ```
192+
///
193+
/// You can alternatively use [`core::iter::successors`].
182194
pub fn iterate<St, F>(initial_value: St, f: F) -> Iterate<St, F>
183195
where
184196
F: FnMut(&St) -> St,

0 commit comments

Comments
 (0)