Skip to content

Instantly share code, notes, and snippets.

@martintrojer
Created June 7, 2013 21:34
Show Gist options
  • Save martintrojer/5732577 to your computer and use it in GitHub Desktop.
Save martintrojer/5732577 to your computer and use it in GitHub Desktop.
Options are collections
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