Skip to content

Instantly share code, notes, and snippets.

@purefn
Created October 25, 2012 16:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save purefn/3953655 to your computer and use it in GitHub Desktop.
Save purefn/3953655 to your computer and use it in GitHub Desktop.
scala> val o: Option[Int] = Some(5)
o: Option[Int] = Some(5)
scala> val l: List[Int] = List(10)
l: List[Int] = List(10)
scala> l flatMap (_ => o)
res1: List[Int] = List(5)
scala> o flatMap (_ => l)
<console>:10: error: type mismatch;
found : List[Int]
required: Option[?]
o flatMap (_ => l)
^
scala> val m: Map[Int, Int] = Map(1 -> 2)
m: Map[Int,Int] = Map(1 -> 2)
scala> l flatMap (_ => m)
res3: List[(Int, Int)] = List((1,2))
scala> m flatMap (_ => l)
res4: scala.collection.immutable.Iterable[Int] = List(10)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment