Skip to content

Instantly share code, notes, and snippets.

@bigjason
Created May 13, 2014 17:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bigjason/7b38fc61d1c46d98bbc3 to your computer and use it in GitHub Desktop.
Save bigjason/7b38fc61d1c46d98bbc3 to your computer and use it in GitHub Desktop.
scala> (1 to 100).map(n => if(n > 10) None else Some(n))
res1: scala.collection.immutable.IndexedSeq[Option[Int]] = Vector(Some(1), Some(2), Some(3), Some(4), Some(5), Some(6), Some(7), Some(8), Some(9), Some(10), None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None)
scala> (1 to 100).flatMap(n => if(n > 10) None else Some(n))
res2: scala.collection.immutable.IndexedSeq[Int] = Vector(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment