2023-05-29 13:39:08 -04:00
|
|
|
// When performing operations on elements within a collection, iterators are
|
|
|
|
// essential. This module helps you get familiar with the structure of using an
|
|
|
|
// iterator and how to go through elements within an iterable collection.
|
2020-08-04 07:57:01 -04:00
|
|
|
|
2023-02-24 08:51:03 -05:00
|
|
|
fn main() {
|
2024-04-17 17:34:27 -04:00
|
|
|
// You can optionally experiment here.
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
#[test]
|
|
|
|
fn iterators() {
|
2024-06-27 20:07:56 -04:00
|
|
|
let my_fav_fruits = ["banana", "custard apple", "avocado", "peach", "raspberry"];
|
2020-08-04 07:57:01 -04:00
|
|
|
|
2024-06-27 20:07:56 -04:00
|
|
|
// TODO: Create an iterator over the array.
|
2024-06-27 20:26:35 -04:00
|
|
|
let mut fav_fruits_iterator = todo!();
|
2020-08-04 07:57:01 -04:00
|
|
|
|
2024-06-27 20:07:56 -04:00
|
|
|
assert_eq!(fav_fruits_iterator.next(), Some(&"banana"));
|
2024-06-27 20:26:35 -04:00
|
|
|
assert_eq!(fav_fruits_iterator.next(), todo!()); // TODO: Replace `todo!()`
|
2024-06-27 20:07:56 -04:00
|
|
|
assert_eq!(fav_fruits_iterator.next(), Some(&"avocado"));
|
2024-06-27 20:26:35 -04:00
|
|
|
assert_eq!(fav_fruits_iterator.next(), todo!()); // TODO: Replace `todo!()`
|
2024-06-27 20:07:56 -04:00
|
|
|
assert_eq!(fav_fruits_iterator.next(), Some(&"raspberry"));
|
2024-06-27 20:26:35 -04:00
|
|
|
assert_eq!(fav_fruits_iterator.next(), todo!()); // TODO: Replace `todo!()`
|
2024-04-17 17:34:27 -04:00
|
|
|
}
|
2020-08-04 07:57:01 -04:00
|
|
|
}
|