Add an iterate function to core::iter
Implementation by Kevin Ballard. The function returns an Unfold iterator producing an infinite stream of results of repeated applications of the function, starting from the provided seed value.
This commit is contained in:
@@ -833,3 +833,12 @@ fn test_min_max_result() {
|
||||
let r = MinMax(1i,2);
|
||||
assert_eq!(r.into_option(), Some((1,2)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_iterate() {
|
||||
let mut it = iterate(|x| x * 2, 1u);
|
||||
assert_eq!(it.next(), Some(1u));
|
||||
assert_eq!(it.next(), Some(2u));
|
||||
assert_eq!(it.next(), Some(4u));
|
||||
assert_eq!(it.next(), Some(8u));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user