Created
August 28, 2013 16:18
-
-
Save seraphr/6367931 to your computer and use it in GitHub Desktop.
collect!
This file contains 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
case class Data(opt: Option[String], value: Int) | |
def d(o: String, v: Int) = Data(Some(o), v) | |
def n(v: Int) = Data(None, v) | |
val tList = List(d("a", 1), d("b", 2), n(10), d("c", 3), n(0)) | |
tList.collect { | |
case Data(Some(o), v) => v | |
} | |
tList.collect { | |
case Data(Some(o), v) => (o, v) | |
} |
This file contains 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
scala> tList.collect { | |
| case Data(Some(o), v) => v | |
| } | |
res3: List[Int] = List(1, 2, 3) | |
scala> tList.collect { | |
| case Data(Some(o), v) => (o, v) | |
| } | |
res4: List[(String, Int)] = List((a,1), (b,2), (c,3)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment