2023-05-29 18:39:08 +01: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 12:57:01 +01:00
|
|
|
|
2023-02-24 13:51:03 +00:00
|
|
|
fn main() {
|
2024-04-17 22:34:27 +01:00
|
|
|
// You can optionally experiment here.
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
#[test]
|
|
|
|
fn iterators() {
|
2024-06-28 01:07:56 +01:00
|
|
|
let my_fav_fruits = ["banana", "custard apple", "avocado", "peach", "raspberry"];
|
2020-08-04 12:57:01 +01:00
|
|
|
|
2024-06-28 01:07:56 +01:00
|
|
|
// TODO: Create an iterator over the array.
|
2024-06-28 01:26:35 +01:00
|
|
|
let mut fav_fruits_iterator = todo!();
|
2020-08-04 12:57:01 +01:00
|
|
|
|
2024-06-28 01:07:56 +01:00
|
|
|
assert_eq!(fav_fruits_iterator.next(), Some(&"banana"));
|
2024-06-28 01:26:35 +01:00
|
|
|
assert_eq!(fav_fruits_iterator.next(), todo!()); // TODO: Replace `todo!()`
|
2024-06-28 01:07:56 +01:00
|
|
|
assert_eq!(fav_fruits_iterator.next(), Some(&"avocado"));
|
2024-06-28 01:26:35 +01:00
|
|
|
assert_eq!(fav_fruits_iterator.next(), todo!()); // TODO: Replace `todo!()`
|
2024-06-28 01:07:56 +01:00
|
|
|
assert_eq!(fav_fruits_iterator.next(), Some(&"raspberry"));
|
2024-06-28 01:26:35 +01:00
|
|
|
assert_eq!(fav_fruits_iterator.next(), todo!()); // TODO: Replace `todo!()`
|
2024-04-17 22:34:27 +01:00
|
|
|
}
|
2020-08-04 12:57:01 +01:00
|
|
|
}
|