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

Clarify the purpose of getOrElse #104

Merged
merged 2 commits into from
Jun 8, 2018

Conversation

emma-burrows
Copy link
Contributor

Just a little tweak to make it clearer to beginners that getOrElse will return the wrapped value if the Option is a Some, and the provided default value if it is None (since there seemed to be some confusion in the comments on this section).

@FRosner
Copy link
Member

FRosner commented Jun 7, 2018

Thanks for the PR @emma-burrows. Sorry I didn't respond earlier I was a bit busy.

@@ -35,7 +35,7 @@ object Options extends FlatSpec with Matchers with org.scalaexercises.definition
* }
* }}}
*
* Using `getOrElse` we can provide a default value ("No value") when the optional argument (`None`) does not exist:
* Using `getOrElse`, we can extract the value if the `Option[A]` is a `Some[A]`, and provide a default value ("No value") when the optional argument (`None`) does not exist:
Copy link
Member

Choose a reason for hiding this comment

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

I think the whole sentence is a bit clumsy.

Maybe we can rewrite it to something like this:

Using getOrElse, we can extract the value if it exists, or return a provided default value. If we have a Some(x) we can return x, and for None we return the default value.

What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I think in general, more numerous, shorter sentences are best. I'll update the PR as suggested.

@FRosner
Copy link
Member

FRosner commented Jun 7, 2018

Thanks a lot! I'm gonna wait until tomorrow if someone else has any feedback. Otherwise I'll merge it :)

@FRosner FRosner merged commit 0fdc520 into scala-exercises:master Jun 8, 2018
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.

2 participants