Last active
August 22, 2018 16:03
-
-
Save adekunleba/5bffc9fb97378d6a5fef789be4152a52 to your computer and use it in GitHub Desktop.
Scala Cheatsheets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //Extracting Values from Optional in Scala | |
| //a. This works well if you have a defined value for your else | |
| val value = Some("Data") | |
| value.getOrElse("No Value") | |
| //b Using match you can extract the value and do anything you want with it | |
| value match { | |
| case Some(i) => println(s"There is a value $i") | |
| case _ => println("There is nothing in value") | |
| } | |
| //b.ii - The values can be extracted into other collections | |
| var finalValue = List[String]() | |
| value match { | |
| case Some(i) => finalValue ::= i | |
| case _ => println("There is nothing in value") | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment