summaryrefslogtreecommitdiff
path: root/solutions/18_iterators/iterators1.rs
diff options
context:
space:
mode:
authormo8it <mo8it@proton.me>2024-06-28 02:07:56 +0200
committermo8it <mo8it@proton.me>2024-06-28 02:07:56 +0200
commitcf9041c0e42120199e09e74e65c52d69c00db19c (patch)
treeb98970867c3aac317800e1513a4dfd6c5f61f061 /solutions/18_iterators/iterators1.rs
parent746cf6863dee8f676596b07e74bad1a19fa2579e (diff)
iterators1 solution
Diffstat (limited to 'solutions/18_iterators/iterators1.rs')
-rw-r--r--solutions/18_iterators/iterators1.rs27
1 files changed, 26 insertions, 1 deletions
diff --git a/solutions/18_iterators/iterators1.rs b/solutions/18_iterators/iterators1.rs
index 4e18198..93a6008 100644
--- a/solutions/18_iterators/iterators1.rs
+++ b/solutions/18_iterators/iterators1.rs
@@ -1 +1,26 @@
-// Solutions will be available before the stable release. Thank you for testing the beta version 🥰
+// 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.
+
+fn main() {
+ // You can optionally experiment here.
+}
+
+#[cfg(test)]
+mod tests {
+ #[test]
+ fn iterators() {
+ let my_fav_fruits = ["banana", "custard apple", "avocado", "peach", "raspberry"];
+
+ // Create an iterator over the array.
+ let mut fav_fruits_iterator = my_fav_fruits.iter();
+
+ assert_eq!(fav_fruits_iterator.next(), Some(&"banana"));
+ assert_eq!(fav_fruits_iterator.next(), Some(&"custard apple"));
+ assert_eq!(fav_fruits_iterator.next(), Some(&"avocado"));
+ assert_eq!(fav_fruits_iterator.next(), Some(&"peach"));
+ assert_eq!(fav_fruits_iterator.next(), Some(&"raspberry"));
+ assert_eq!(fav_fruits_iterator.next(), None);
+ // ^^^^ reached the end
+ }
+}