1 scala> val l = List(1, 2, 3)
l: List[Int] = List(1, 2, 3)
2 scala> l map {x => Some(x) }
res14: List[Some[Int]] = List(Some(1), Some(2), Some(3))
3 scala> l flatMap {x => Some(x) }
res15: List[Int] = List(1, 2, 3)
4 scala> val f = (x: Int) => Some(x)
f: Int => Some[Int] = <function1>
5 scala> l map f
res16: List[Some[Int]] = List(Some(1), Some(2), Some(3))
6 scala> l flatMap f
<console>:13: error: type mismatch;
found : Int => Some[Int]
required: Int => scala.collection.GenTraversableOnce[?]
l flatMap f
An implicit conversion is needed to turn Options into TraversableOnces,
allowing you to mix List and Option monads with flatMap and get a List
back. Someone more knowledgeable should comment, but until then, my
guess is that such a conversion can't be found or applied in the case
where the function f is passed in, for some reason.
{x => Some(x) }
Int => GenTraversableOne[Int]
Int => Some[Int]
> <mailto:scala-user+unsub...@googlegroups.com>.