for (lst <- Some(List(1,2,3)); x <- lst) yield x
is translated to
Some(List(1,2,3)).flatMap(lst => lst.map(x => x))
The flatMap
method on Option
expects a function that returns an Option
, but you're passing a function that returns a List
and there is no implicit conversion from List
to Option
.
Now if you convert the Option
to a list first, the flatMap
method of List
will be called instead, which expects a function returning a List
, which is what you are passing to it.
In this particular case, I think the most idiomatic solution is
Some(List(1,2,3)).flatten.toList