Skip to content

Added iterators5.rs exercise.#646

Merged
manyinsects merged 2 commits into
rust-lang:mainfrom
apogeeoak:iterator
Apr 21, 2021
Merged

Added iterators5.rs exercise.#646
manyinsects merged 2 commits into
rust-lang:mainfrom
apogeeoak:iterator

Conversation

@apogeeoak

Copy link
Copy Markdown
Contributor

Added an iterator exercise that counts values in a hash map that equal a given value.

Incorporates more iterator methods into the exercises. Provides a use case for the fold method.

@jfchevrette

jfchevrette commented Feb 10, 2021

Copy link
Copy Markdown
Contributor

👍 I like the idea behind this exercise

@apogeeoak

Copy link
Copy Markdown
Contributor Author

This exercise does not use actual progress data. It only simulates progress. The strings that are used as keys can be anything. They just happen to be filenames from the exercises. If the exercise files are renamed, exercises are deleted, or new exercises are added this exercise will still work.

@jfchevrette

Copy link
Copy Markdown
Contributor

Sorry for the confusion @apogeeoak, I'll update my previous comment

@manyinsects manyinsects left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall a great concept! I have some ideas that could make this exercise a little easier to approach, feel free to implement those.

@@ -0,0 +1,113 @@
// iterators5.rs

// Rustling progress is modelled using a hash map. The name of the exercise is

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Rustling progress is modelled using a hash map. The name of the exercise is
// Let's reimplement a simple version of Rustlings exercise progress!
// This will be modelled using a hash map. The name of the exercise is

// Make the code compile and the tests pass.

// I AM NOT DONE

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally, I would leave comments somewhere in this exercise with notes that explain:

  • What a "stack" is (aka a vec of hashmaps)
  • That you probably shouldn't touch the _for methods, but rather implement the iterative version in the other methods
  • A delineator above the tests module telling the user not to touch what's below it

count
}

fn count(map: &HashMap<String, Progress>, value: Progress) -> usize {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rename these to count_iterator or something, to keep them separate from the _for methods.

@apogeeoak

Copy link
Copy Markdown
Contributor Author

Thanks for the suggestions. I improved the exercise explanation and clarified which functions need modified.

I renamed stack to collection to avoid confusion and added a comment describing the collection.

@manyinsects manyinsects left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

@manyinsects manyinsects merged commit 79cc657 into rust-lang:main Apr 21, 2021
@apogeeoak apogeeoak deleted the iterator branch April 21, 2021 14:00
ppp3 pushed a commit to ppp3/rustlings that referenced this pull request May 23, 2022
dmoore04 pushed a commit to dmoore04/rustlings that referenced this pull request Sep 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants