Skip to content

Conversation

@jonathanpallant
Copy link
Member

Simplified the solution and tidied up some of the exercise text whilst I was here.

Closes #197

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Apr 24, 2025

Deploying ferrous-systems-rust-exercises with  Cloudflare Pages  Cloudflare Pages

Latest commit: 4910285
Status: ✅  Deploy successful!
Preview URL: https://c9b3921e.ferrous-systems-rust-exercises.pages.dev
Branch Preview URL: https://fixes.ferrous-systems-rust-exercises.pages.dev

View logs

Simplified the solution and tidied up some of the exercise text whilst I was here.

Closes #197
@jonathanpallant
Copy link
Member Author

Force pushed after I found some typos I'd made. Also, I replaced "turbo fish" with "turbofish" as per the docs.

Comment on lines 14 to 16
.fold(0, |acc, elem| acc + elem);
// Also works
//.sum::<i32>();
Copy link
Member

Choose a reason for hiding this comment

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

I would simply put .sum(); here. Unlike filter and map that are popular, fold is not used too often. Half of Itertools methods are fold variants with more descriptive methods. May as well call sum because we work with numbers here. Turbofish is not needed, because there's i32 on line 9 already.

Suggested change
.fold(0, |acc, elem| acc + elem);
// Also works
//.sum::<i32>();
.sum();

Copy link
Member Author

Choose a reason for hiding this comment

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

Good idea. Also updated the text above to match, and the solution.

Copy link
Member Author

Choose a reason for hiding this comment

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

11 |     let result = reader.lines()
   |         ^^^^^^
...
15 |         .sum();
   |          --- type must be known at this point

oops

@jonathanpallant
Copy link
Member Author

I have appeased the type checker.

@jonathanpallant jonathanpallant merged commit a882ad4 into main May 1, 2025
22 checks passed
@jonathanpallant jonathanpallant deleted the fixes branch May 20, 2025 14:38
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.

Readme for iterators exercise has typo which makes test fail

3 participants