Skip to content

Instantly share code, notes, and snippets.

@dipakc
Created November 9, 2012 05:46
Show Gist options
  • Select an option

  • Save dipakc/4043947 to your computer and use it in GitHub Desktop.

Select an option

Save dipakc/4043947 to your computer and use it in GitHub Desktop.
RefactoringOptListFlatten
object OptListFlatten {
///////////////
val aList = List(Some(10), None, Some(20))
for {
x <- aList
if (x.isDefined)
} yield {
x.get
}
//-------------
for {
xOpt <- aList
x <- xOpt
} yield x
//-------------
aList filter (_.isDefined) map (_.get)
//-------------
aList.flatten
//-------------
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment