Skip to content

Add Option to cheatsheet #1277

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

Merged
merged 1 commit into from
Feb 8, 2019
Merged

Conversation

ashawley
Copy link
Member

@ashawley ashawley commented Feb 1, 2019

Give a quick introduction to how Option works, and also show many of the useful methods on Some and None and the equivalent pattern match.

I removed the use of Option from the pattern match section at the begging of the cheatsheet.

Preview:

https://ashawley.github.io/docs.scala-lang/cheatsheets/index.html

The original:

https://docs.scala-lang.org/cheatsheets/index.html

@ashawley ashawley changed the title Add options to cheatsheet Add Option to cheatsheet Feb 1, 2019
Copy link
Contributor

@kotobotov kotobotov left a comment

Choose a reason for hiding this comment

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

some minor improvements

if trimmed.length != 0
upper <- Some(trimmed.toUpperCase)
} yield upper
println(upper.getOrElse(""))</code></pre></td>
Copy link
Contributor

Choose a reason for hiding this comment

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

do we really need to println something?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's not required, but it seems useful to show that the value is no longer an Option. Many of the other examples in the cheatsheet use println.

@Philippus
Copy link
Member

maybe add flatten as well?

@ashawley
Copy link
Member Author

ashawley commented Feb 4, 2019

I added flatten:

optionOfOption match {
  case Some(Some(x)) => Some(x)
  case _             => None
}

@ashawley ashawley force-pushed the cheatsheet-options branch 2 times, most recently from c335b66 to 17e21d8 Compare February 6, 2019 15:49
@SethTisue SethTisue merged commit e84d22a into scala:master Feb 8, 2019
@ashawley ashawley deleted the cheatsheet-options branch June 18, 2019 13:49
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.

4 participants