Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SimpleDB: add a solution or link to with more match #47

Open
amanjeev opened this issue Oct 24, 2023 · 3 comments
Open

SimpleDB: add a solution or link to with more match #47

amanjeev opened this issue Oct 24, 2023 · 3 comments

Comments

@amanjeev
Copy link
Member

amanjeev commented Oct 24, 2023

https://github.com/ferrous-systems/rust-exercises/blob/main/exercise-book/src/simple-db.md

Add more match. more match more match! chant grows!

cc @miguelraz

Tasks

Preview Give feedback
No tasks being tracked yet.
@miguelraz
Copy link
Contributor

I think it would be nice to sequence this exercise in a way that helps people leverage the pattern matching powers of match, not just showing the solution at the end.

Also, there can be a trailing data corner case by not checking that the first newline is the end of the data.

Leave it as an extra credit, along with a "try to do it with a single match"?

@jonathanpallant
Copy link
Member

I had an idea to simplify this example - don't require the terminating newline, and change the spec to say that all leading and trailing whitespace is trimmed before processing.

@jonathanpallant
Copy link
Member

jonathanpallant commented Feb 28, 2024

Running through this again, I think the first-pass solution should probably be:

  1. Does this string have exactly one newline in it?

    input.chars().filter(|c| *c == '\n').count() == 1
  2. Does this string have a newline at the end?

    input.chars().last() == Some('\n')

This builds on the iterator lesson, without needing to know weird string functions.

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

No branches or pull requests

3 participants