Created
October 10, 2014 21:24
-
-
Save duncanmak/f19b414f4dc4d923ea83 to your computer and use it in GitHub Desktop.
This file contains hidden or 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> class Foo | |
defined class Foo | |
scala> val l = List(1,2,3) | |
l: List[Int] = List(1, 2, 3) | |
scala> def f(i: Int): Option[Int] = if (i % 2 == 0) Some(i) else None | |
f: (i: Int)Option[Int] | |
scala> l.map(f) | |
res0: List[Option[Int]] = List(None, Some(2), None) | |
scala> l.flatMap(f) | |
res1: List[Int] = List(2) | |
scala> def f[T <: Foo](i: T): Option[T] = ??? | |
f: [T <: Foo](i: T)Option[T] | |
scala> l.flatMap(f) | |
<console>:11: error: polymorphic expression cannot be instantiated to expected type; | |
found : [T <: Foo]T => Option[T] | |
required: Int => scala.collection.GenTraversableOnce[?] | |
l.flatMap(f) | |
^ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment