Created
October 25, 2012 16:00
-
-
Save purefn/3953655 to your computer and use it in GitHub Desktop.
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 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