comprehensive-rust icon indicating copy to clipboard operation
comprehensive-rust copied to clipboard

"Strings and Iterators" solution that uses let-else

Open pwnall opened this issue 2 years ago • 1 comments

This PR is intended as the start of a discussion -- I'm not entirely sure it's an improvement as-is. I came up with the solution below for the Day 2 Afternoon exercise.

I was looking for something conceptually similar to the current solution -- zip(), but extending one of the iterators. So, I think the current solution teaches a trick that will be useful in practice, and should stand. I think my solution may be a bit easier to follow.

pwnall avatar Jun 19 '23 22:06 pwnall

Hi @pwnall,

Looking at the solution I wrote again, I definitely think it could benefit from some comments! Your solution is actually simpler to understand since it is more explicit with the call to next().

I would prefer to not include two full solutions (they'll go out of sync and they overload the solution slide). So could we instead use your solution and then explain the current "trick" in a comment? The double Option<Option<&str>> type is a bit weird and so I never truly liked the trick :smile:

mgeisler avatar Jun 21 '23 11:06 mgeisler

Sorry, for the slow reply. I'll turn this around in the next couple of days.

pwnall avatar Jun 27 '23 17:06 pwnall

@mgeisler Please take another look?

pwnall avatar Jun 28 '23 22:06 pwnall

@mgeisler Thank you very much for the quick review!

pwnall avatar Jun 29 '23 16:06 pwnall