Created
June 7, 2013 21:34
-
-
Save martintrojer/5732577 to your computer and use it in GitHub Desktop.
Options are collections
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> val a = List(Map("a"->1), Map("b"->2), Map("c"->3,"b"->4)) | |
a: List[scala.collection.immutable.Map[String,Int]] = List(Map(a -> 1), Map(b -> 2), Map(c -> 3, b -> 4)) | |
scala> a find (_ contains "b") map (_("b")) | |
res0: Option[Int] = Some(2) | |
scala> a find (_ contains "c") map (_("b")) | |
res1: Option[Int] = Some(4) | |
scala> a find (_ contains "d") map (_("b")) | |
res2: Option[Int] = None |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment