Skip to content

Instantly share code, notes, and snippets.

@adekunleba
Last active August 22, 2018 16:03
Show Gist options
  • Select an option

  • Save adekunleba/5bffc9fb97378d6a5fef789be4152a52 to your computer and use it in GitHub Desktop.

Select an option

Save adekunleba/5bffc9fb97378d6a5fef789be4152a52 to your computer and use it in GitHub Desktop.
Scala Cheatsheets
//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